idrathermacro
Programmer
Hi - I'm trying to revise a sub macro and I can't figure out the syntax for multiple "if then" statements. I want the macro to place custom headers and footers on all tabs in a workbook, except for certain tabs. Those tabs will be any tabs that end with a ">" or a end with "BoP" or are entitled any of the following: "TOC" or "Cover" or "End" or "Disclaimer" or "Letter of presentation" or "LoP" or "Glossary".
I thought I'd be able to simply add along to the If or with more "or" but apparently not.
Here's the macro:
Sub ApplyHeaderFooter(ByVal control As IRibbonControl)
'
' Apply header/footer to all tabs
'
Dim Check As Integer
Check = MsgBox("This will replace the header/footer contents of the entire workbook. Are you sure you want to continue?", vbYesNoCancel)
If Check = vbYes Then
For Each aSheet In Worksheets
If Right(Trim(aSheet.Name), 1) = ">" Or Right(Trim(aSheet.Name), 3) = "BoP" Or aSheet.Name = "TOC" Or aSheet.Name = "Cover" Or aSheet.Name = "End" Or aSheet.Name = "Disclaimer" Or aSheet.Name = "Letter of presentation" Or aSheet.Name = "LoP" Or aSheet.Name = "Glossary" Then
Else
With aSheet.PageSetup
.LeftHeader = ""
.CenterHeader = "&""Arial,Normal""&8&A"
.RightHeader = _
"&""Arial,Normal""&8Draft - Tentative and preliminary" & Chr(10) & "Subject to change"
.LeftFooter = _
"&""Arial,Normal""&8This information is subject in all respects to the terms and conditions of our engagement letter," & Chr(10) & "including restrictions on disclosure of this deliverable to third parties."
.CenterFooter = ""
.RightFooter = "&""Arial,Normal""&8&P"
End With
End If
Next aSheet
End If
I thought I'd be able to simply add along to the If or with more "or" but apparently not.
Here's the macro:
Sub ApplyHeaderFooter(ByVal control As IRibbonControl)
'
' Apply header/footer to all tabs
'
Dim Check As Integer
Check = MsgBox("This will replace the header/footer contents of the entire workbook. Are you sure you want to continue?", vbYesNoCancel)
If Check = vbYes Then
For Each aSheet In Worksheets
If Right(Trim(aSheet.Name), 1) = ">" Or Right(Trim(aSheet.Name), 3) = "BoP" Or aSheet.Name = "TOC" Or aSheet.Name = "Cover" Or aSheet.Name = "End" Or aSheet.Name = "Disclaimer" Or aSheet.Name = "Letter of presentation" Or aSheet.Name = "LoP" Or aSheet.Name = "Glossary" Then
Else
With aSheet.PageSetup
.LeftHeader = ""
.CenterHeader = "&""Arial,Normal""&8&A"
.RightHeader = _
"&""Arial,Normal""&8Draft - Tentative and preliminary" & Chr(10) & "Subject to change"
.LeftFooter = _
"&""Arial,Normal""&8This information is subject in all respects to the terms and conditions of our engagement letter," & Chr(10) & "including restrictions on disclosure of this deliverable to third parties."
.CenterFooter = ""
.RightFooter = "&""Arial,Normal""&8&P"
End With
End If
Next aSheet
End If