Insert text inside footer

A

Alex St-Pierre

Hi,
I have an excel macro that open a word document and add text at the left of
the footer (with left alignment). Does anyone know how can I add the page
number at the right of the footer (with right alignment) ? I don't know how
to add 2 differents texts with differents alignments in the same footer.

The actual macro is the following:
Sub Word_Footer()
Dim WdApp As Object 'Word.Application
Dim myDoc As Object 'Document
Dim SourceFileI As String
Dim DestinationFileI As String

On Error Resume Next
Set WdApp = GetObject("", "Word.Application")
If WdApp Is Nothing Then
Set WdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
WdApp.Visible = True

SourceFileI = "C:\SourceFile.doc"
DestinationFileI = "C:\DestinationFile.doc"

FileCopy SourceFileI, DestinationFileI
Set myDoc = WdApp.Documents.Open(Filename:=DestinationFileI)
myDoc.sections(1).footers(1).Range.Text = Nom
myDoc.sections(1).footers(1).Range.Select
myDoc.sections(1).footers(1).Range.Font.Bold = False
myDoc.sections(1).footers(1).Range.Font.Name = "Arial"
myDoc.sections(1).footers(1).Range.Font.Size = 10
myDoc.sections(1).footers(1).Range.ParagraphFormat.Alignment = 0
myDoc.Save
myDoc.Close
Set myDoc = Nothing
Set WdApp = Nothing
End Sub()
Thank you !
 
M

macropod

Hi Alex,

If you format the footer paragraph/style so that it's got a right-alignment
tab set against the right margin, your code could then insert a Chr(9) after
your first text string, followed by the page number. Your code doesn't
attach any specific template, so the document you're creating will be based
on the 'Normal.dot' template. You have three choices here:
.. Modify the 'Normal.dot' template so that the footer style already has the
formatting you want
.. Modify the footer style in the document after opening it
.. Attach a different template with the footer style that has the formatting
you want

For the page number, I'd suggest using a PAGE field, which will show the
correct page number on all pages, not just the number inserted into the
footer.

Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top