How to save to specific directory when doing ExportAsFixedFormat?

romtoss

New Member
Joined
Nov 29, 2016
Messages
9
Hello!

I have a workbook with 39 tabs that need to be saved individually as PDFs. To save myself time, I created a macro that does this. Code is below. Problem is, I can't get the PDFs to be saved/exported to a specific folder consistently. I've tried a few solutions I looked up online, but I must be doing something wrong. I tried "ChDir" followed by a path, but they always save to My Documents and I don't want them there. Can anyone provide a simple solution here?

Code:
Sub Save_PDFs()


    For n = 1 To 39

    ActiveSheet.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=ActiveSheet.Name, _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=False, _
        IgnorePrintAreas:=False, _
        OpenAFterPublish:=False

        ActiveSheet.Next.Select

    Next n


End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try this, changing the saveInFolder string as required.
Code:
Public Sub Save_Each_Sheet_As_PDF()

    Dim saveInFolder As String
    Dim ws As Worksheet
    
    saveInFolder = "C:\path\to\folder\"
    If Right(saveInFolder, 1) <> "\" Then saveInFolder = saveInFolder & "\"
    
    For Each ws In Worksheets
        ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=saveInFolder & ws.Name & ".pdf", _
            Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=False
    Next
    
End Sub
 
Upvote 0
Hmm, unfortunately that didn't work either. They still save to My Documents, regardless of what path I specify.
 
Upvote 0
John's solution should work. What string are you assigning to saveInFolder?
 
Upvote 0
John's solution should work. What string are you assigning to saveInFolder?

I've tried several, both on our network (here at work) and local to my machine. No matter what I do, it saves to My Documents. Currently I have this:

Code:
    Dim saveInFolder As String
    saveInFolder = "C:\Users\rostom\Desktop\"
 
Upvote 0
Can you post the complete code that you're using?

Here it is.

Code:
Sub Save_PDF()


    Dim saveInFolder As String
    saveInFolder = "C:\Users\rostom\Desktop\"


    Worksheets("Template - Rep Detail").Select


    For n = 1 To 39
        ActiveSheet.Next.Select
        Cells.EntireColumn.AutoFit


        ActiveSheet.ExportAsFixedFormat _
            Type:=xlTypePDF, _
            Filename:=ActiveSheet.Name, _
            Quality:=xlQualityStandard, _
            IncludeDocProperties:=False, _
            IgnorePrintAreas:=False, _
            OpenAFterPublish:=False
    Next n


End Sub
 
Upvote 0
While you've assigned saveInFolder the path, you haven't included it for your path in the argument for Filename. Also, you may want include the file extension as well. Try...

Code:
Filename:=saveInFolder & ActiveSheet.Name & ".pdf", _
 
Last edited:
Upvote 0
While you've assigned saveInFolder the path, you haven't included it for your path in the argument for Filename. Also, you may want include the file extension as well. Try...

Code:
Filename:=saveInFolder & ActiveSheet.Name & ".pdf", _


Doh! That worked... silly me. Thank you so much!!
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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