Search code examples
vbams-wordpowerpointfootermultiple-columns

Creating 3 column Word footer from PowerPoint VBA


I am creating Word document from PowerPoint, copying slides in a table etc. Then I make a footer like this :

Const wdSeekCurrentPageFooter = 10
Const wdFieldEmpty = -1
...
wrdApp.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
wrdApp.Selection.TypeText Text:="Column1" & " " & CStr(Date) & " " & "Page "
wrdApp.Selection.Fields.Add Range:=wrdApp.Selection.Range, _
Type:=wdFieldEmpty, Text:="PAGE  ", PreserveFormatting:=True
wrdApp.Selection.TypeText Text:=" of "
wrdApp.Selection.Fields.Add Range:=wrdApp.Selection.Range, _
Type:=wdFieldEmpty, Text:="NUMPAGES  ", PreserveFormatting:=True

So I get 3 info in footer, but I can make them appear nice using Tabs, I would like something like

  • Manual add footer, built-in, Blank(Three Columns) or

  • Footer, insert 3 texts, edit, insert alignment tabs

But I can't make any of these 2 solutions to work from PowerPoint VBA.

  1. When looping through templates I can't see "Building Blocks.dotx"

  2. This code breaks (named argument not found)

    wrdApp.Selection.Range.InsertAlignmentTab Alignment:=0,Relative:=0,Leader:=0
    

I need solution to work in Offices 2007 2010 and 2013. Any ideas how to make this happen ?


Solution

  • InsertAlignmentTab only has 2 parameters, Alignment and RelativeTo (not Relative)

    For VBA to "see" the names of parameters, you need to make a reference (Tools->References...) to the Word object model. But since you are targetting multiple versions of Office, you are probably trying to avoid that, in which case, use positional parameter passing

    wrdApp.Selection.Range.InsertAlignmentTab 0, 0
    

    re. looping for Building Blocks, I would guess that you cannot guarantee that Building Blocks.dotx exists.