0
votes

I currently have an excel file that generates a pdf page with left and right footers using the following code.

Set wsSig_Page = Worksheets("Signature Page")
wsSig_Page.PageSetup.LeftFooter = sLeft_Footer
wsSig_Page.PageSetup.RightFooter = sRight_Footer

sLeft_Footer and sRight_Footer are both strings.

My issue is that I'm now required to generate the pdf using a word document. I've gotten most of the formatting needed but I'm stuck trying to find the replacement to PageSetup.LeftFooter and PageSetup.RightFooter.

The word document is created and populated by an excel macro.

EDIT: My code to generate a new word doc is the following

Set wdApp = CreateObject("Word.Application")    
Set wd = wdApp.Documents.Add

I currently don't have any code relating to adding footers to the word document because I don't know how to have two multi line sections appear inline (one on the left and one on the right) in the footer of the word document.

Using an excel worksheet was easy because it has LeftFooter and RightFooter as part of the properties of PageSetup. This is not the case in word.

EDIT 2: Old code for footer.

 Sub Insert_Footer(Optional Hide_Macro As Boolean) Dim wsSig_Page As
 Worksheet Dim wsAgreement As Worksheet Dim wsAgreement_Data As
 Worksheet Dim Signature_Page_Count As Integer Dim Agreement_Page_Count
 As Integer Dim Total_Page_Count As Integer Dim Replace_Tag_Array() As
 String Dim Replace_Text_Array() As String Dim sLeft_Footer As String
    Dim sRight_Footer As String Dim i As Integer

    'MsgBox (wd.Range.Information(wdNumberOfPagesInDocument))
    Set wsSig_Page = Worksheets("Signature Page")
    Set wsAgreement = Worksheets("Agreement")
    Set wsAgreement_Data = GetAgreementDataWorksheet()

    iRow_End = wsSig_Page.Range("A2000").End(xlUp).row
    Call Worksheet_Methods.Scroll_To_Location(wsSig_Page.Range("A" & iRow_End))
    Signature_Page_Count = ExecuteExcel4Macro("Get.document(50,""Signature Page"")")

    'iRow_End = wsAgreement.Range("A2000").End(xlUp).row
    'Call Worksheet_Methods.Scroll_To_Location(wsAgreement.Range("A" & iRow_End))
    'Agreement_Page_Count = ExecuteExcel4Macro("Get.document(50,""Agreement"")")

    Agreement_Page_Count = wd.Range.Information(wdNumberOfPagesInDocument)

    Total_Page_Count = Signature_Page_Count + Agreement_Page_Count + Worksheets("Form").Range("Field_Schedule_Page_Numbers").value

    sLeft_Footer = wsAgreement_Data.Range("A2").value

    Replace_Tag_Array() = Split(wsAgreement_Data.Range("D2").value, "|")
    Replace_Text_Array() = Split(wsAgreement_Data.Range("E2").value, "|")

    For i = 0 To UBound(Replace_Tag_Array)
        sLeft_Footer = Replace(sLeft_Footer, Replace_Tag_Array(i), Replace_Text_Array(i))
    Next

    sRight_Footer = Replace(wsAgreement_Data.Range("A3").value, "<TOTAL_PAGE_NUMBER>", Total_Page_Count)

    If Len(sLeft_Footer) + Len(sRight_Footer) > 254 Then
        Set rRange = Worksheets("Form Data").Range("Table_Abr")
        sString = Replace_Text_Array(1)
        Replace_Text_Array(1) = Range("Abr_Text").value
        sLeft_Footer = wsAgreement_Data.Range("A2").value
        For i = 0 To UBound(Replace_Tag_Array)
            sLeft_Footer = Replace(sLeft_Footer, Replace_Tag_Array(i), Replace_Text_Array(i))
        Next
    End If

    wsSig_Page.PageSetup.LeftFooter = sLeft_Footer


    wsSig_Page.PageSetup.RightFooter = Replace("&09Page &P+" & Agreement_Page_Count & " of <TOTAL_PAGE_NUMBER>", "<TOTAL_PAGE_NUMBER>", Total_Page_Count)


End Sub
1
Please also show us an relevant excerpt of the Excel code to generate the Word document (declaration and instantiation of the Word objects, whatever you have that works with the document footer). Also, I recommend you open such a document in Word and take a look at the Footer. Try typing something, pressing TAB twice, then typing some more. Is that what you want?Cindy Meister
Since I've updated and I think I have posted the info you were asking may you let me know what info I missed that you asked for.Tolure
Test in Word: go to the footer, insert a two-column, one-row table. Format the second column to be right-aligned. Is this what you need? If yes, record performing that action in a macro to get a starting point.Cindy Meister
In all my word documents I set up a three column table to manage left, right and centre footers/headers. In this case, you simple find the table in the header or footer and put your information in the left or right cell.AJD

1 Answers

1
votes

Unlike Excel, Word doesn't have left, centre and right headers & footers - depending on the page setup, Word has a first page, even page and primary header & footers (for controlling what appears on the first page, even pages and all other pages) in every Section. For a given header or footer, if you want three separate entries on a single line, you can format a paragraph with the appropriate alignment (e.g. centred/justified) and tab-stops (possibly 3 centred, or one each of left, centre and right), then insert tab characters into the text you're inserting. Alternatively, for multi-line inputs especially, you could insert a 3-column table with the appropriate cell formatting and send the outputs to the relevant cells.

You might add a table to the primary page footer of the First Section in a document using code like:

With wd
  .Tables.Add Range:=.Sections.First.Footers(wdHeaderFooterPrimary).Range, NumRows:=1, NumColumns:=3, AutoFitBehavior:=wdAutoFitFixed
  With .Sections.First.Footers(wdHeaderFooterPrimary).Range.Tables(1).Range
    .Cells(1).Range.Text = "Text for cell 1"
    .Cells(2).Range.Text = "Text for cell 2"
    .Cells(3).Range.Text = "Text for cell 3"
  End With
End With

If you're using late binding, as appears to be the case, you'll need to replace the named constants (wdHeaderFooterPrimary, wdAutoFitFixed) with the corresponding values (1, and 0, respectively). You can then tell Word what to put in each of the cells, as indicated above. You can also format each cell individually.