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
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Does everyone have write permission to the C drive?
 
Upvote 0
Try testing to see if the folder exists.
VBA Code:
Sub Save_to_PDF()
' Save_to_PDF Macro
'
    Dim FolderName As String, FileName As String

    FolderName = "C:\Users\113891\Desktop\"
    FileName = "Universal Arbitration Form April 2020.pdf"

    With CreateObject("Scripting.FileSystemObject")
        If .FolderExists(FolderName) Then
            ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
                FileName:=FolderName & FileName, Quality:=xlQualityStandard, _
                IncludeDocProperties:=True, IgnorePrintAreas:=False, _
                OpenAfterPublish:=True
        Else
            MsgBox "Folder: " & vbCr & vbCr & FolderName & vbCr & vbCr & "does not exist", vbCritical
        End If
    End With
End Sub
 
Upvote 0
Try testing to see if the folder exists.
VBA Code:
Sub Save_to_PDF()
' Save_to_PDF Macro
'
    Dim FolderName As String, FileName As String

    FolderName = "C:\Users\113891\Desktop\"
    FileName = "Universal Arbitration Form April 2020.pdf"

    With CreateObject("Scripting.FileSystemObject")
        If .FolderExists(FolderName) Then
            ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
                FileName:=FolderName & FileName, Quality:=xlQualityStandard, _
                IncludeDocProperties:=True, IgnorePrintAreas:=False, _
                OpenAfterPublish:=True
        Else
            MsgBox "Folder: " & vbCr & vbCr & FolderName & vbCr & vbCr & "does not exist", vbCritical
        End If
    End With
End Sub
This works on my machine, but I don't think we have write access Do you know if there is a workaround?
 
Upvote 0
If you don't have write access to the folder you are trying to save the .pdf to, then I think you are at a brick wall. The only workaround would be to find another location that you have write access to.
 
Upvote 0
As rlv01 states if not everyone has write access to the C drive then you need to find a location that you all have access to (or get IT to update everyone's security level if they are willing).
The generic path to everyone's desktop is...
VBA Code:
Dim DesktopAddress As String
DesktopAddress = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator
MsgBox DesktopAddress
 
Upvote 0
If you don't have write access to the folder you are trying to save the .pdf to, then I think you are at a brick wall. The only workaround would be to find another location that you have write access to.
Is there a way to generate the pdf, via a script, and then prompt to user to select the location to save the file?
 
Upvote 0
Try something like..

VBA Code:
Sub Save_to_PDF()
    ' Save_to_PDF Macro
    '
    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
Try something like..

VBA Code:
Sub Save_to_PDF()
    ' Save_to_PDF Macro
    '
    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
 

Attachments

  • Error.jpg
    Error.jpg
    147.9 KB · Views: 11
Upvote 0

Forum statistics

Threads
1,213,501
Messages
6,114,010
Members
448,543
Latest member
MartinLarkin

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