I'm using VBA script to print 4 sheets from the same workbook to a PDF.
It was working until yesterday, now different sheets are different widths in the PDF. I even went back to an older backup of the Workbook that had made the PDF correctly and it now has the same issue. ???
I tried to remove the sheet reordering, the script was doing and now there are three different widths. ???
If I manual highlight the sheet tabs and then print to PDF they are the correct width again. Shown in the second pic above.
This is the code now with most everything commented out so it's just selecting the sheets and printing them.
It was working until yesterday, now different sheets are different widths in the PDF. I even went back to an older backup of the Workbook that had made the PDF correctly and it now has the same issue. ???
I tried to remove the sheet reordering, the script was doing and now there are three different widths. ???
If I manual highlight the sheet tabs and then print to PDF they are the correct width again. Shown in the second pic above.
This is the code now with most everything commented out so it's just selecting the sheets and printing them.
VBA Code:
Sub PrintCoverAndMainSheet()
Dim FilePath As String
Dim DefaultPath As String
Dim FileName As String
Dim CurrentDateTime As String
Dim desiredOrder As Variant
Dim i As Long
Dim cover_ws As Worksheet
Dim report_ws As Worksheet
Dim Devation_ws As Worksheet
' ' Set references to the source and destination sheets
' Set cover_ws = ThisWorkbook.Sheets("Cover Sheet")
' Set report_ws = ThisWorkbook.Sheets("BMS vs Azure DB")
' Set Devation_ws = ThisWorkbook.Sheets("Deviation Exceeded")
' Call CopyRowsDeviationExceeded
' Call CopyRowsMissingPoints
' ' Store the PageSetup.Pages.Count in cells T2, U2, and V2
' report_ws.Range("T2").Value = cover_ws.PageSetup.pages.Count
' report_ws.Range("U2").Value = report_ws.PageSetup.pages.Count
' report_ws.Range("V2").Value = Devation_ws.PageSetup.pages.Count
' Get the current date and time
CurrentDateTime = Format(Now, "mm-dd-yyyy_hh-mm_AMPM")
' Set the default file name with the current date and time appended
FileName = "Datalake & BMS Data Verification Report " & CurrentDateTime & ".pdf"
' Get the default path for the user's Documents folder with the file name
DefaultPath = Environ("USERPROFILE") & "\Documents\" & FileName
' Prompt the user to select the file path with a default file name
FilePath = Application.GetSaveAsFilename(InitialFileName:=DefaultPath, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Save PDF As")
' If the user cancels, exit the macro
If FilePath = "False" Then Exit Sub
' ' Set the original sheet to a variable and get its index
' Set OriginalActiveSheet = ActiveSheet
' Set OriginalSheet = ThisWorkbook.Sheets("Cover Sheet")
' OriginalIndex = OriginalSheet.Index
' ' Move "Cover Sheet" to be the first sheet
' OriginalSheet.Move Before:=ThisWorkbook.Sheets(1)
' Select the sheets in the desired order
Sheets(Array("Cover Sheet", "BMS vs Azure DB", "Deviation Exceeded", "Missing Points")).Select
' Export the selected sheets to PDF at the chosen location
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FilePath
' ' Move "Cover Sheet" back to its original position
' If OriginalIndex > 1 Then
' OriginalSheet.Move After:=ThisWorkbook.Sheets(OriginalIndex)
' End If
' ' Select the original sheet again
' OriginalActiveSheet.Select
End Sub
Last edited: