vba code to create a pdf giving error message

JannetteChristie

Board Regular
Joined
Dec 14, 2015
Messages
130
Office Version
  1. 365
My code is as follows:

JobName = ActiveSheet.Range("Salesman") & " - Weekly Report: w/c " & Sheets("Analysis").Range("FromDate")
TempFileName = Environ$("temp") & "" & JobName & ".pdf"
' TempFileName = "c:\Users" & JobName & ".pdf"


ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=TempFileName, _
OpenAfterPublish:=False

I am getting the error message Run-time error '-2147024773 (8007007b)': Document not saved.

Watch : : TempFileName : "C:\Users\jchri\AppData\Local\Temp\Frazer Ross - Weekly Report: w/c 04/06/2018.pdf"
Watch : : JobName : "Frazer Ross - Weekly Report: w/c 04/06/2018" : String : Module2.SubmitData

I have no idea what is wrong with the code - can anyone help ?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
I think your issue is with the file name. "/" are invalid characters for file name (in your "w/c 04/06/2018" part).
You cannot use those in your file name.
 
Upvote 0
Thanks for that, however I have removed the slashes and still get the same error code.

?JobName
Frazer Ross - Weekly Report: w.c 04.06.2018
?TempFileName
C:\Users\jchri\AppData\Local\Temp\Frazer Ross - Weekly Report: w.c 04.06.2018.pdf
 
Upvote 0
Colons aren't allowed either in file names (missed that one earlier).

A good way to test/debug these sort of things is to try it on a simple name first, like "test.pdf".
If that works, but your big one doesn't, then you know the issue is with your file name.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,204
Members
453,022
Latest member
RobertV1609

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