I'm new to VB so forgive my ignorance. I'm thinking I'm starting with something simple but not getting it. I'd like to have a word document template that, when opened, requests office location name then enters the proper address and phone number for that location in the footer.
I thought to use a drop down list to select the location, I.E. Denver, LA, SF, NY etc. then have VB enter the proper address and phone number in the footer. I can get VB to put an address or PH in the footer but not stacked. The last one overwrites the first.
The code I am starting with is:
Sub FooterAddress()
FooterAddress Macro
With ActiveDocument.Sections(1)
.Footers(wdHeaderFooterPrimary).Range.Text = "Local Office City" .Footers(wdHeaderFooterPrimary).Range.Text = "123 My Street | City, ST 12345-6789" .Footers(wdHeaderFooterPrimary).Range.Text = "Phone 800.123.4567"
End With
End Sub
I tried to use formatting codes for headers and footers to choose the font and center the text but just got errors. Didn't even try changing the color yet.
I can't get the dropdown to launch the script and I can't get the template to launch the dropdown on open either.
Am I going at this wrong? Is there a better way to approach this problem? Can someone point me to a good resource that I can read to learn this stuff?
Thank you
CodePudding user response:
For example:
Sub FooterAddress()
Application.ScreenUpdating = False
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Text = _
"Local Office City" & vbCr & _
"123 My Street | City, ST 12345-6789" & vbCr & _
"Phone 800.123.4567"
Application.ScreenUpdating = True
End Sub
CodePudding user response:
In the footer, create bookmarks for each line (Insert>Bookmark). Then write to the bookmarks with:
ActiveDocument.Sections(1).Footer(wdHeaderFooterPrimary).Range.Bookmarks("Bookmarkname").Range.Text = "AddressText"