Export as pdf button broken

willisjk545

New Member
Joined
Jun 9, 2017
Messages
1
I have a button that uses the following code to print the information in the range of cells to a PDF:

Code:
Private Sub CommandButton1_Click()ActiveWorkbook.Worksheets("Sheet1").Range("L2:L35").ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=Filename, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
OpenAfterPublish:=True

End Sub

This worked until a couple days ago and now it gives me the following error:
"runtime error 1004: Document not saved. The file may be open, or an error may have been encountered when saving"

I attempt to debug and after it steps over the above code I get the following:
"Run-time error '1004':
Application-defined or object-defined error"

I have shared this with other people and it works for a short time on their computers then gives them the same issue. I had not changed any library or directory information, I then tried to save to desktop and reload but issue remains.

Any help would be appreciated.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I'm no VBA wizard by any means but in the distant past I had a similar problem where Excel was somewhat randomly choosing to focus on the button, not the range. I think I eventually solved it by using .Activate -at least at the Range level and maybe Workbook level too.
 
Upvote 0

Forum statistics

Threads
1,216,354
Messages
6,130,150
Members
449,560
Latest member
mattstan2012

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