All,
Apologies ahead of time for the ugly code. I am a complete novice at this and have used inputs for forums like yourself to kludge together something that appears to work, except that I can't get it to run successfully when I push play. I've seen a lot of posts about only working when steeping through (F8) but none of the answers seemed to do it for me. I'm sure there is a golden rule I'm breaking that will make my code 1000x better, so any inputs you all have would be greatly appreciated.
So this code is used to apply a header to a swath of tabs in an Excel spreadsheet. Date and file name with a particular format. It runs successfully if I put a breakpoint around the end of it ( ActiveWorkbook.Sheets("TOC").Range("A2").Select) or if I step through using F8. Without it, the date doesn't get applied to the rest of the sheets (only the "TOC" sheet that I specified). Please let me know if anything stands out and thank you in advance!
'Variables
Dim fso As New Scripting.FileSystemObject
Sub ConfigSMPV()
Sheets("Title").Visible = False
Sheets("SystemConfig").Visible = False
Sheets("Sheet ii").Visible = False
Sheets("TOC").Activate
For Each VisableSheet In Sheets
With VisableSheet
If .Visible = True Then .Select Replace:=False
End With
'Debug.Print cntr
'cntr = cntr + 1
Next VisableSheet
'Application.PrintCommunication = False
With ActiveWorkbook.Sheets("TOC").PageSetup
.RightHeader = vbCr & fso.GetBaseName(ActiveWorkbook.Name)
End With
With ActiveWorkbook.Sheets("TOC").PageSetup
.LeftHeader = vbCr & Format(ActiveWorkbook.Sheets("SystemConfig").Range("C15").Value, "mmmm d, yyyy")
End With
ActiveWorkbook.Sheets("TOC").Range("A2").Select
'Application.Wait (Now + TimeValue("0:00:10"))
Sheets("Title").Visible = True
Sheets("SystemConfig").Visible = True
Sheets("SystemConfig").Activate
End Sub
Apologies ahead of time for the ugly code. I am a complete novice at this and have used inputs for forums like yourself to kludge together something that appears to work, except that I can't get it to run successfully when I push play. I've seen a lot of posts about only working when steeping through (F8) but none of the answers seemed to do it for me. I'm sure there is a golden rule I'm breaking that will make my code 1000x better, so any inputs you all have would be greatly appreciated.
So this code is used to apply a header to a swath of tabs in an Excel spreadsheet. Date and file name with a particular format. It runs successfully if I put a breakpoint around the end of it ( ActiveWorkbook.Sheets("TOC").Range("A2").Select) or if I step through using F8. Without it, the date doesn't get applied to the rest of the sheets (only the "TOC" sheet that I specified). Please let me know if anything stands out and thank you in advance!
'Variables
Dim fso As New Scripting.FileSystemObject
Sub ConfigSMPV()
Sheets("Title").Visible = False
Sheets("SystemConfig").Visible = False
Sheets("Sheet ii").Visible = False
Sheets("TOC").Activate
For Each VisableSheet In Sheets
With VisableSheet
If .Visible = True Then .Select Replace:=False
End With
'Debug.Print cntr
'cntr = cntr + 1
Next VisableSheet
'Application.PrintCommunication = False
With ActiveWorkbook.Sheets("TOC").PageSetup
.RightHeader = vbCr & fso.GetBaseName(ActiveWorkbook.Name)
End With
With ActiveWorkbook.Sheets("TOC").PageSetup
.LeftHeader = vbCr & Format(ActiveWorkbook.Sheets("SystemConfig").Range("C15").Value, "mmmm d, yyyy")
End With
ActiveWorkbook.Sheets("TOC").Range("A2").Select
'Application.Wait (Now + TimeValue("0:00:10"))
Sheets("Title").Visible = True
Sheets("SystemConfig").Visible = True
Sheets("SystemConfig").Activate
End Sub