VBA save as PDF Error 1004

Shakeable_Drip

Board Regular
Joined
May 30, 2023
Messages
52
Office Version
  1. 365
Platform
  1. Windows
my sub to save as PDF is failing and I cant figure out why. "runtime error 1004: document not save. the Document may be open, or an error may have been encountered when saving"
The print Debug gives me a good path, am I using this incorrectly? debug= "strSourceFolder\TEST 999.pdf"
Ah well I think the error is in the save path, I dont know how to correct this

VBA Code:
Sub SaveAsPDF()
Dim sht1 As Worksheet
Dim sht2 As Worksheet
Dim strSourceFolder As String
Dim order As String
Dim SaveLocation As String

Set sht1 = Sheets("HELPER")
Set sht2 = Sheets("REPORTS")
strSourceFolder = ActiveWorkbook.Path 'Source path
order = sht1.Cells(13, 22)
SaveLocation = "strSourceFolder" & "\" & order & ".pdf"
'Debug.Print SaveLocation
sht2.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:=SaveLocation

End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Ah it was the quotes around strSourceFolder
VBA Code:
SaveLocation = strSourceFolder & "\" & order & ".pdf"

so much facepalm
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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