As-Lag
Structural
- Aug 6, 2019
- 56
Hello
I have moved some VBA from a Windows 7 machine running Excel 2007 onto a Windows 11 running Excel 2022. The code selects five sheets, one at a time, does some basic formatting and then exports the sheet to a folder called Output as a pdf. On the Win 7 machine, I use CutePDF to print; on the Win 11 machine, I want to use the Microsoft print to PDF printer.
When I go to print the pages, the pages are printed correctly but are placed in "Documents", not "Output". Any clues why the Win 11 machine is not responding as the Win 7 machine please? Is it to do with the ChDir bit of the path? Regards.
I have moved some VBA from a Windows 7 machine running Excel 2007 onto a Windows 11 running Excel 2022. The code selects five sheets, one at a time, does some basic formatting and then exports the sheet to a folder called Output as a pdf. On the Win 7 machine, I use CutePDF to print; on the Win 11 machine, I want to use the Microsoft print to PDF printer.
When I go to print the pages, the pages are printed correctly but are placed in "Documents", not "Output". Any clues why the Win 11 machine is not responding as the Win 7 machine please? Is it to do with the ChDir bit of the path? Regards.
Code:
Sub DoNagPrint()
'Stop
'Set the printer
Application.Dialogs(xlDialogPrinterSetup).Show
'Set the printout path
ChDir "D:\Office\New Age Glass\Excel\Output"
'Get Sheet data
Dim projectReference, propertiesReference, propertiesReferenceE, notesReference, shutteringReference As String
projectReference = Sheets("NAG").Range("A1").Value
propertiesReference = Sheets("NAG").Range("I3").Value
propertiesReferenceE = Sheets("NAG").Range("I3").Value + "E"
notesReference = Left(projectReference, 8) & "-4" & Range("G4").Value & Range("C4")
shutteringReference = Left(projectReference, 8) & "-5" & Range("G4").Value & Range("C4")
'Create file names
Dim aFileName(5) As String
Dim i As Integer
aFileName(1) = projectReference & " - Calculations.pdf"
aFileName(2) = propertiesReference & " - Properties.pdf"
aFileName(3) = propertiesReferenceE & " - Properties.pdf"
aFileName(4) = notesReference & " - Notes.pdf"
aFileName(5) = shutteringReference & " - Shuttering.pdf"
'Write to files
For i = 1 To 5
Sheets(i).Activate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:= _
aFileName(i), Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Next i
Sheets("NAG").Activate
MsgBox "Done"
End Sub