VBA Footer

tgizmo

New Member
Joined
Jul 9, 2010
Messages
7
Why doesn't my telephone number show in the bottom right footer with the following code?
This is a telephone number (###.###.####) but I've tried various formats. Everything else works.
How do I make this run automatically with any change in the worksheet? I currently have to run the macro for it to update.
Bonus Question: What does "_" mean at the end of the lines after the line break?
Thanks for helping...

Sub SetFooter()
' custom footer

Dim wb As Workbook
Dim wsProfile As Worksheet
Dim strCompany As String
Dim strAddress As String
Dim strCity As String
Dim strZip As String
Dim strContact As String
Dim strEmail As String
Dim strTel As String

Set wb = ThisWorkbook
Set wsProfile = wb.Sheets("Company Profile")

strCompany= wsProfile.Range("pCompany").Value
strAddress = wsProfile.Range("pAddress").Value
strCity = wsProfile.Range("pCity").Value
strZip = wsProfile.Range("pZip").Value
strContact = wsProfile.Range("pContact").Value
strEmail = wsProfile.Range("pContactEmail").Value
strTel = wsProfile.Range("pContactTel").Value

With wsProfile.PageSetup
.LeftFooter = _
"&8" & Space(10) & strCompany & Chr(10) & _
"&8" & Space(10) & strAddress & Chr(10) & _
"&8" & Space(10) & strCity & ", TX" & strZip
.CenterFooter = ""
.RightFooter = _
"&8" & strContact & Chr(10) & _
"&8" & strEmail & Chr(10) & _
"&8" & strTel
End With
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hey tgizmo,

Great to hear from you! You're awesome and I'm honored to help. Try this. It worked for me. OK, so I answered my own question a few minutes after posting. Maybe this will help someone else....

Sub SetFooter()
' custom footer

Dim wb As Workbook
Dim wsProfile As Worksheet
Dim strCompany As String
Dim strAddress As String
Dim strCity As String
Dim strZip As String
Dim strContact As String
Dim strEmail As String
Dim strTel As String

Set wb = ThisWorkbook
Set wsProfile = wb.Sheets("Company Profile")

strCompany = wsProfile.Range("pCompany").Value
strAddress = wsProfile.Range("pCompanyAddress").Value
strCity = wsProfile.Range("pCompanyCity").Value
strZip = wsProfile.Range("pCompanyZip").Value
strBroker = wsProfile.Range("pCompanyContact").Value
strEmail = wsProfile.Range("pCompanyContactEmail").Value
strTel = Format(wsProfile.Range("pCompanyContactTel").Value, "###"".""###"".""####")

With ActiveSheet.PageSetup
.LeftFooter = _
"&8" & Space(10) & "&B" & strCompany & "&B" & Chr(10) & _
Space(10) & strAddress & Chr(10) & _
Space(10) & strCity & ", TX " & strZip & "&8"
.CenterFooter = ""
.RightFooter = _
"&8" & strContact & Chr(10) & _
strEmail & Chr(10) & _
strTel & "&8"

End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,579
Members
449,174
Latest member
chandan4057

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top