vba code not setting footer on all sheets

dinotom

Active Member
Joined
Aug 2, 2009
Messages
357
Can anyone tell me why the footer is only being set on some sheets and not on all of them like it should be? Each sheet is printing as as it should and with the right amount of copies.


Code:
Sub PrintPositionSheets()
    Dim ws As Worksheet
    Dim iCopies As Integer, sSheetName As String, dDate As Date
        
   Application.PrintCommunication = False
   For Each ws In Worksheets
        sSheetName = ws.Name
        If Time > 0.66804 Then
            dDate = dDate + 1
        Else
            dDate = Date
        End If
             
        With Sheets(sSheetName).PageSetup
'            .OddAndEvenPagesHeaderFooter = True
'            .EvenPage.CenterFooter.Text = "Positions for " & dDate
'            .FirstPage.CenterFooter.Text = "Positions for " & dDate
            [B].CenterFooter = "Positions for " & dDate[/B]
            .PrintQuality = 600
            .Orientation = xlLandscape
            .PaperSize = xlPaperLetter
            .FirstPageNumber = xlAutomatic
            .Order = xlDownThenOver
            .BlackAndWhite = False
            .Zoom = 100
       
        
        If sSheetName = "TD-Firm" Or sSheetName = "TD-KL&TD" Or sSheetName = "TD-FirmPRG" Or sSheetName = "BATLMGMT" Then
            iCopies = 3
        Else
            iCopies = 2
        End If
        If Not sSheetName = "Notes" Then
       Sheets(sSheetName).PrintOut Copies:=iCopies, Collate:=True, _
            IgnorePrintAreas:=False
        End If
     End With
    Next ws
    Application.PrintCommunication = True
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
In the sheets where the footer isn't being set properly, is anything appearing in the footer - anything at all?

By the way, is this correct:-
Code:
        If Time > 0.66804 Then
            [B][COLOR=blue]dDate[/COLOR][/B] = [COLOR=red][B]dDate[/B][/COLOR] [B][COLOR=magenta]+ 1[/COLOR][/B]
        Else
            dDate = Date
        End If
because the first time through that IF, dDate could be zero so you're just assigning + 1 to dDate.
 
Upvote 0
Good bug catch BUT the footer would then be the text only and not the date. It is not even putting the text portion in the footer.
 
Upvote 0
Oh quite - that's why I asked whether anything at all was appearing in the footer. That was a "by the way".

So... do the 'faulty' sheets have anything in common which each other which the correctly-printing sheets don't have?
 
Upvote 0

Forum statistics

Threads
1,215,463
Messages
6,124,962
Members
449,200
Latest member
indiansth

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