PPT.TableBackground in MS PowerPoint 2010 to Set Background Fill in Tables in VB.NET

In this article I am going to explain about how to Set Background Fill in Tables in a Microsoft PowerPoint 2010 presentation.
  • 3797

Introduction

In this article I am going to explain about how to Set Background Fill in Tables in a Microsoft PowerPoint 2010 presentation. For this we use PPT.TableBackground in Microsoft PowerPoint 2010. Using PPT.TableBackground we can set the background fill properties for each cell of a table in a Microsoft PowerPoint 2010 presentation.

Microsoft Office 2010 offer some powerful tools, using this tools you can create application. Using Microsoft Visual Basic for Applications (VBA) you can create your own application according to your need. These application can performer some specific task.

For creating application we can use

  • VBA host of Excel 2010
  • VBA host of PowerPoint 2010
  • VBA host of Word 2010

NOTE : OneNote 2010 is not a VBA host.

Code that we use in this application are given below

Sub WorkWithTableBackground()

    Dim vip As Presentation
    vip = ActivePresentation 

    ' Create a slide with a table on it:

    Dim vip1 As Slide
    vip1 = vip.Slides.Add(2, ppLayoutTable)
 
    Dim vip2 As Table
    vip2 = vip1.Shapes.AddTable(4, 4).Table

    
' Fill the table with data:
    FillTable(vip2)
 
    
' Retrieve Background property:
    Dim tb As TableBackground
    tb = vip2.Background 

    ' Should be able to do this:
    tb.Fill.ForeColor.ObjectThemeColor = msoThemeColorAccent2

    ' This procedure sets the cell color:
    SetTableColor(vip2, msoThemeColorAccent2) 

    ' This procedure sets the cell texture:
    SetTableTexture(vip2, msoTextureCork)

End Sub 

Sub FillTable(vip2 As Table) 

    ' Fill a table with sample data.
    Dim r1 As 
Integer
    Dim c1 As 
Integer
 
    For c1 = 1 To vip2.Columns.Count
        vip2.Cell(1, c1).Shape.TextFrame.TextRange.Text = "Heading " & c1
    Next c1 

    Dim shp As Shape 

    For r1 = 2 To vip2.Rows.Count
        For c1 = 1 To vip2.Columns.Count
            shp = vip2.Cell(r1, c1).Shape
            shp.TextFrame.TextRange.Text = "Cell " & r1 & ", " & c1
            shp.Fill.Visible = msoFalse
        Next c1
    Next r1

End
 Sub
 

Sub
 SetTableColor(vip2 As Table, themeColor As MsoThemeColorIndex)
 
    Dim r1 As 
Integer
    Dim c1 As 
Integer
 
    For c1 = 1 To vip2.Columns.Count
        For r1 = 1 To vip2.Rows.Count
            Dim Fill As 
Integer
            vip2.Cell(r1, c1).Shape.Fill.ForeColor.ObjectThemeColor = themeColor
        Next r1
    Next c1

End
 Sub
 

Sub
 SetTableTexture(vip2 As Table, texture As MsoPresetTexture)
 
    Dim r1 As 
Integer
    Dim c1 As 
Integer
 
    For c1 = 1 To vip2.Columns.Count
        For r1 = 1 To vip2.Rows.Count
            Dim Fill As 
Integer
            vip2.Cell(r1, c1).Shape.Fill.PresetTextured(texture)
        Next r1
    Next c1


End
 Sub

Steps for creating Application

Step 1 : Start Microsoft PowerPoint 2010 : 
 

1.jpg
 

Step 2 : Using Alt + F11 Key Start Visual Basic for Applications (VBA) Window :

2.jpg
 

Step 3 : Select on VBAProject(Presentation 1) : 
 

3.jpg
 

Step 4 : Right Click On VBAProject(Presentation 1) ==> Goto Insert==> Goto Module & click on Module:

4.jpg

5.jpg
 

Step 5 : Write Code in Visual Basic for Applications (VBA) Window :

Clipboard06.jpg
 

Step 6 : Run Application by using F8 again and again :

Step 7 : Macros window will open, Select Macros name and click on Run Button :

Clipboard05.jpg
 

Step 8 : Output of Application :

There are three output of this application

Clipboard02.jpg

Clipboard03.jpg

Clipboard01.jpg

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.