Runtime Error 1004

Tgpitch16

New Member
Joined
Jul 8, 2015
Messages
25
Office Version
  1. 365
Platform
  1. Windows
I have the code below to export to a pdf file. However, when I change the file location to just "C:\Universal Arbitration Form April 2020.pdf", it throws a runtime error 1004. This form will be utilized for the masses and each computer is setup differently, thus the reason for the file location change. What else am I missing?

Sub Save_to_PDF()
'
' Save_to_PDF Macro
'

'
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\113891\Desktop\Universal Arbitration Form April 2020.pdf", Quality _
:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub
 
For some reason I didn't paste the Dim when copying/pasting...

Rich (BB code):
Sub Save_to_PDF()
    ' Save_to_PDF Macro
    '
    Dim FileName As String, myfile_Path As String
    
    FileName = "Universal Arbitration Form April 2020.pdf"

    myfile_Path = Application.GetSaveAsFilename(InitialFileName:=FileName, FileFilter:="Adobe PDF File_ (*.pdf), *.pdf")
    

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
                                    FileName:=myfile_Path, Quality:=xlQualityStandard, _
                                    IncludeDocProperties:=True, IgnorePrintAreas:=False, _
                                    OpenAfterPublish:=True

End Sub
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
For some reason I didn't paste the Dim when copying/pasting...

Rich (BB code):
Sub Save_to_PDF()
    ' Save_to_PDF Macro
    '
    Dim FileName As String, myfile_Path As String
   
    FileName = "Universal Arbitration Form April 2020.pdf"

    myfile_Path = Application.GetSaveAsFilename(InitialFileName:=FileName, FileFilter:="Adobe PDF File_ (*.pdf), *.pdf")
   

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
                                    FileName:=myfile_Path, Quality:=xlQualityStandard, _
                                    IncludeDocProperties:=True, IgnorePrintAreas:=False, _
                                    OpenAfterPublish:=True

End Sub
Perfect, thank you for your help
 
Upvote 0
You're welcome
One last ask.

If a user executes the command, but instead of saving, presses cancel, is there a way to not have the pdf generate? It currently generates with the file name as False.pdf
 
Upvote 0
Try...
VBA Code:
Sub Save_to_PDF()
    ' Save_to_PDF Macro
    '
    Dim FileName As String, myfile_Path As String
   
    FileName = "Universal Arbitration Form April 2020.pdf"

    myfile_Path = Application.GetSaveAsFilename(InitialFileName:=FileName, FileFilter:="Adobe PDF File_ (*.pdf), *.pdf")
    If myfile_Path = "False" Then Exit Sub

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
                                    FileName:=myfile_Path, Quality:=xlQualityStandard, _
                                    IncludeDocProperties:=True, IgnorePrintAreas:=False, _
                                    OpenAfterPublish:=True

End Sub
 
Upvote 0
Try...
VBA Code:
Sub Save_to_PDF()
    ' Save_to_PDF Macro
    '
    Dim FileName As String, myfile_Path As String
  
    FileName = "Universal Arbitration Form April 2020.pdf"

    myfile_Path = Application.GetSaveAsFilename(InitialFileName:=FileName, FileFilter:="Adobe PDF File_ (*.pdf), *.pdf")
    If myfile_Path = "False" Then Exit Sub

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
                                    FileName:=myfile_Path, Quality:=xlQualityStandard, _
                                    IncludeDocProperties:=True, IgnorePrintAreas:=False, _
                                    OpenAfterPublish:=True

End Sub
Perfect, thanks again.
 
Upvote 0

Forum statistics

Threads
1,215,831
Messages
6,127,146
Members
449,364
Latest member
AlienSx

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