Run time error 5 when trying to save pdf to folder

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,934
Office Version
  1. 2007
Platform
  1. Windows
Using the command button to save a file of which the extension is pdf i see the following error.
Ive checked the folder is there & also the path to the folder & both are correct but im unaware as to what the issue is.

EaseUS_2025_02_19_17_49_49.jpg


Checking the code when i debug i see this line in yellow.

Rich (BB code):
    strFileName = "C:\Users\there\Desktop\REMOTES ETC\DR\DR COPY INVOICES\" & Range("L4").Value & ".pdf"
    With ActiveSheet
      .ExportAsFixedFormat Type:=xlTypePDF, fileName:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
    End With 'CURRENT INVOICE IS NOW SAVED
 
Yes
Dopey shop i bought it from installed Windows & why they used that im confused

Before it would have been my name Ian So ive changed pretty much all my code & just the 1 or 2 files left thus being one of them.

In that line of code its flagged up is there a work around we can try to see what the issue is, Maybe change pdf to a word doc but i tried a few extensions but none worked or i just git them wrong.
xlsm .xlsm ,Doc and also doc
 
Upvote 0
If it worked on your other computer and all you've changed is the path.....

C:\Users\there\Desktop\REMOTES ETC\DR\DR COPY INVOICES

the above is copied from your posted code
if you copy it, then open File Explorer and paste it into the name bar (or box, whatever)
does it open the folder you're wanting ?
If it does then afraid I don't know.
 
Upvote 0
So i copied the code above & pasted it into the search box, hit return & the correct folder opened
The code i supplied is the path to the folder on my new pc.

Ive manually checked it & also done the above mentioned & fine.
 
Upvote 0
So a line or two up has the following code.
I changed the current invoice number to an invoice number that is already in the folder in question.
Because of this i see the Msgbox pop up saying WAS NOT SAVED ETC

So the code is actually looking & has found the correct folder.
Strange why it wont save the current invoice there.





Rich (BB code):
    strFileName = "C:\Users\there\Desktop\REMOTES ETC\DR\DR COPY INVOICES\" & Range("L4").Value & ".pdf"
    If Dir(strFileName) <> vbNullString Then
      MsgBox "INVOICE " & Range("L4").Value & " WAS NOT SAVED AS IT ALLREADY EXISTS" & vbNewLine & vbNewLine & "PLEASE CHECK FILE IN FOLDER THAT WILL NOW OPEN.", vbCritical + vbOKOnly, "INVOICE NOT SAVED MESSAGE"
      VBA.Shell "explorer.exe /select, " & "" & strFileName & "", vbNormalFocus 'DUPLICATE INVOICE FOUND
    Exit Sub
    End If
 
Upvote 0
hOW CAN MY CODE BE WRITTEN SO WE SAVE AS A WORD DOC JUST TO TEST IT.

jUST WONDERING IF SOMETHING ISNT TICKED IN THAT TOOLS REFERENCES BOX ?
 
Upvote 0
In a few other sheets where i save the file & have it printed they all do the same & when i debug they all point to the same line of code.
 
Upvote 0

Forum statistics

Threads
1,226,834
Messages
6,193,213
Members
453,780
Latest member
Nguyentam2007

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