Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Setting the path in windows 11

Setting the path in windows 11

Setting the path in windows 11

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 --> vba

Sub DoNagPrint()
'Set the printer

'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
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:= _
            aFileName(i), Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, _
        Next i

    MsgBox "Done"

End Sub 

RE: Setting the path in windows 11

I very rarely use the print command from VBA, but message no 6 in the thread linked below looks like it should help:


dim myprinter as string
dim printer_name as sttring
printer_name ="name goes here"

myprinter = Application.ActivePrinter
Change_Form.PrintOut Preview:=False, ActivePrinter:=printer_name, PrintToFile:=True, PrToFileName:=PSFileName
Application.ActivePrinter = myprinter

If you include the full path in PSFileName that looks like it should work.

Doug Jenkins
Interactive Design Services

RE: Setting the path in windows 11


I will try out and report back.

RE: Setting the path in windows 11

There is some ambiguity between "current folder" and "default folder" in the online documentation.

Build aFileName explicit and it should work as expected.

RE: Setting the path in windows 11

Dear MintJulep

I was specific with the file name by adding the path to the filename and it works. But why did Excel 2007 - and Excel 2010 - work and not the new Excel?

Regards to you all.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close