ERROR with PDF export by VBA, when the file is open

mahhdy

Board Regular
Joined
Sep 15, 2016
Messages
86
Hi,
I have a user form which exports a form as PDF file with a predefined name format.
I want if the same pdf file is open, VBA returns a message box asking him/her to first close the open file, then retry the export.
Actually, I don't know the error code, the rest should be ok.
Thanks as always.
M
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try this:
Immediately before the line that tries to save the PDF, put:
Code:
On Error Goto PdfExportError
Immediately after the line that tries to save the PDF, put:
Code:
On Error Goto 0
At the very end of the macro, just before End Sub, add the following lines:
Code:
Exit Sub 'prevents the main code execution from running into the error handler
PdfExportError:
MsgBox("Error message to be displayed")
Exit Sub
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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