Right Footer not displaying correct information

mcomp72

Active Member
Joined
Aug 14, 2016
Messages
275
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2011
Platform
  1. Windows
  2. MacOS
I have a workbook where I allow the user to print certain sheets. (There are potentially 30 to choose from, and they can print as few or as many as they want.) They have the option of having the date & time appear on each sheet, in the right footer. The code places this info in the right footer just before printing (technically before a print preview). However, I've discovered it is not displaying the correct time on the sheets except for the first sheet.

Let's say I printed some sheets at 5:58 PM today. Then I went to print those same sheets again at 6:05 PM.

The right footer on the first page would say "Printed on 9/27/2019 @ 6:05 PM", just as it should. However, on all the rest of the pages, the right footer would say "Printed on 9/27/2019 @ 5:58 PM". That makes no sense, because my code is supposed to be setting the Right Footer on each page after the user has pressed the print button (a custom button I've made).

Here's the code I'm using to do this:

Code:
FirstSheetFound = False
SheetsToPrint = ""
SheetName = ""

For i = 1 to 30

    SheetName = "Sheet" & i
    
    If SheetWasChosenToPrint(i) = True Then
    
        If FirstSheetFound = True Then
            SheetsToPrint = SheetsToPrint & "," & SheetName
        Else
            SheetsToPrint = SheetsToPrint & SheetName
            FirstSheetFound = True
        End If
        
        'this places the date & time on the Right Footer of the page, if the user has chosen for it to be there
        ThisWorkbook.Sheets(SheetName).PageSetup.RightFooter = ""
        If IncludeDateTimeFooter = True Then _
           ThisWorkbook.Sheets(SheetName).PageSetup.RightFooter = _
           "Printed on " & Format(Now(), DateFormatToUse) & " @ " _
           & Format(Now(), "h:mm AM/PM")
        
        Debug.Print ThisWorkbook.Sheets(SheetName).PageSetup.RightFooter
        
        'this next sub sets the print area and sets which rows to repeat at the top of each page
        Call SetPrintArea(SheetName)
    
        'in case the sheet is not set to visible, this will do that
        ThisWorkbook.Sheets(SheetName).Visible = xlSheetVisible
    
    End If

Next i

Application.ScreenUpdating = True
ThisWorkbook.Sheets(Split(SheetsToPrint, ",")).PrintOut Preview:=True, IgnorePrintAreas:=False
Application.ScreenUpdating = False

Here is the entire sub of SetPrintArea:

Code:
Sub SetPrintArea(SheetName As String)

Dim LastColumn As Integer
Dim LastColumnLetter As String
Dim NumberOfColumnsDisplayed As Integer
Dim PrintAreaRange As String

NumberOfColumnsDisplayed = ThisWorkbook.Sheets(SheetName).Range("AS8").Value

LastColumn = 8 + NumberOfColumnsDisplayed

LastColumnLetter = Chr(LastColumn + 64)

On Error Resume Next
Application.PrintCommunication = False
On Error GoTo 0

PrintAreaRange = "C4:" & LastColumnLetter & "213"

With ThisWorkbook.Sheets(SheetName).PageSetup

    .PrintArea = Range(PrintAreaRange).Address
    .Orientation = xlLandscape
    '.Zoom = False <-this was causing another issue, so I am commenting it out for now
    .FitToPagesWide = 1
    .FitToPagesTall = False
    .PrintTitleRows = "$4:$9"

End With

End Sub

Can anyone see anything that would be causing this issue? I have looked at the code for a couple of hours now, but I'm not seeing anything wrong. The worst part is, if I step through the code, then the problem DOESN'T OCCUR. That's what makes this one so confusing. I can't see where things are going wrong when I'm debugging because it won't do it when stepping through the code. Has anyone else experienced that before?

I sincerely appreciate any help on this one. It's driving me bonkers.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
By the way, I'm on Windows 10 with the latest version of Excel 365.
 
Upvote 0
I figured it out! In my sub SetPrintArea, I had set Application.PrintCommunication = False, but forgot to set it back to True at the end of the Sub. Once I added that, it worked as it should.
 
Upvote 0

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

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