VBA - Save Worksheet as PDF - Not Working Since 365 Upgrade

lager1001

Board Regular
Joined
May 17, 2019
Messages
88
I have the below code set that has worked for several years for a specific report but is no longer working since Office was upgraded to 365. I am now getting a Run-Time error '1004': Application-defined or object-defined error after the message box asks for confirmation. I'm wondering if has something to do with library resources? Macro security settings appear to be ok. Any ideas?
Sub SendAsPDF
Dim sBlatt As String
Dim sPdfDateiF5 As String
Dim OutApp As Object
Dim OutMail As Object

If MsgBox("Send the order as a E-Mail?", 4, "Frage") = vbYes Then


sPdfDateiF5 = "FilePath" & ".pdf"

(ERROR OCCURS DURING BELOW CODE)
ActiveWorkbook.Sheets("Form Pallet").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=sPdfDateiF5, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False

After this code it sends the attached PDF to a distribution list via Outlook.
 
Does the value in ActiveWorkbook.Sheets("Form Box").Range("E3") contain any illegal characters, such as "\", "/", "<", ">", "?", "[", "]", ":", "|", "*", """"?
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
If the path is correct and you have permission to access the folder, it should work. Just to be sure, enter the following line of code in the Immediate Window and press the ENTER key. If the path is valid, it should return the folder name. Does it return the folder name?

VBA Code:
? Dir("Filepathhere", vbDirectory)
I get "Compile Error: Expected: list separator or )"
 
Upvote 0
It looks like your version of Excel uses something other than a comma ( , ) as a list separator. It probably uses a semi-colon ( ; ). Try the following instead...

VBA Code:
? Dir("Filepathhere"; vbDirectory)

Does it return the folder name? If so, try...

VBA Code:
ActiveWorkbook.ExportAsFixedFormat _
    Type:=xlTypePDF; _
    Filename:="c:\users\domenic\desktop\sample.pdf"; _
    Quality:=xlQualityStandard; _
    IncludeDocProperties:=True; _
    IgnorePrintAreas:=False; _
    OpenAfterPublish:=False

If it works, you'll need to change all your other comma separators to semi-colons.
This gives me a compile error: Expected: End of Statement" error.
 
Upvote 0
As mentioned, that line should be entered in the Immediate Window. Did you enter it in the Immediate Window?
 
Upvote 0
As mentioned, that line should be entered in the Immediate Window. Did you enter it in the Immediate Window?
Hi Domenic,

I had some VBA guys in the office take a look and the code is written as it should be, however it appears to simply run too fast and the steps don't execute and complete in time for the next steps in the code. I put delays in after the steps and now sometimes it works, other times I get the error.
 
Upvote 0

Forum statistics

Threads
1,215,055
Messages
6,122,902
Members
449,097
Latest member
dbomb1414

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