I am creating a Word document from Excel. The creation of the main document and the text works fine with formatting and so on but I am stuck on creating a footer for my document.
Can anyone suggest the code that I need to access the Word footer, write text to it and apply formatting?
Hello,
can you provide some detail about how you do that?I am creating a Word document from Excel.
Maybe post the code you're using and a sample Excel and Word file to play with?
cheers,
This is a shortened version of my code and I have highlighted where the footer processing should go. I have taken out the input and output sheet procesing part and some of the formatting. I suspect that the answer is based on the line of code I have added but I can't seem to work out how to format the footer text (i.e. centre it or change the font size).
'--------------------------------------------------------------------------------------------- Private Sub CommandButton3_Click() ' Create the Word document '--------------------------------------------------------------------------------------------- DotPath = ThisWorkbook.Path FullDotName = DotPath & "<name_of_template>" Set wrdApp = CreateObject("Word.Application") Set wrdDoc = wrdApp.documents.Add(Template:=FullDotName) wrdApp.Visible = True ' Start in the right place wrdApp.ActiveDocument.Bookmarks("StartHere").Select ' Write the contract text out to the output sheet Application.EnableEvents = False '<code to loop through the input sheet and write to the output sheet> Application.EnableEvents = True ' Now write the Word document from the output sheet For ExcelNum = 3 To 253 Step 1 ' Create the document '################### ' <footer processing code needs to be here> ' This code writes the footer but I can't work out how to format it wrdDoc.Sections(1).Footers(1).Range.Text = "I am a footer" '################### With wrdApp ' Insert a table of contents based on the position of ' the variable in the output sheet If ExcelTxtIn = "*tableofcontents*" Then wrdDoc.TablesOfContents.Add _ Range:=wrdApp.Selection.Range, _ RightAlignPageNumbers:=True, _ UseHeadingStyles:=False, _ IncludePageNumbers:=True, _ LowerHeadingLevel:=2, _ UpperHeadingLevel:=1, _ UseHyperlinks:=False, _ HidePageNumbersInWeb:=True, _ UseOutlineLevels:=True wrdDoc.TablesOfContents(1).TabLeader = wdTabLeaderDots wrdDoc.TablesOfContents.Format = wdIndexIndent Else ' Otherwise format the text and replace the the "placeholders" in the ' output sheet with the real values With wrdApp With .Selection .Font.Name = "Times New Roman" .TypeParagraph .Font.Bold = FontBld .Font.Underline = FontUnd ' Now do the replacement of tag with text For Counter = 3 To TCount ExcelTxtOut = Replace(ExcelTxtIn, TagArrNam(Counter), TagArrTxt(Counter)) ExcelTxtIn = ExcelTxtOut Next Counter .TypeText Text:=ExcelTxtOut End With End With End If With .Selection ' Either insert a new line or a new paragraph If ParaNLNP = "New Page" Then .TypeText Text:=Chr(12) If ParaNLNP = "New Paragraph" Then .TypeText Text:=Chr(13) End With End With Next ExcelNum ' Update the TOC if one exists If wrdDoc.TablesOfContents.Count > 0 Then wrdDoc.TablesOfContents(1).Update 'wrdApp.Quit ' close the Word application Set wrdDoc = Nothing Set wrdApp = Nothing End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks