Saving Multiple Worksheets as PDF Files w/Macro - Error

CGDobyns

New Member
Joined
Jan 22, 2025
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
I have a workbook which contains around 180 separate worksheets. Once a year, I need to make updates to all these worksheets and then save each worksheet as a .pdf file with the name of the worksheet and append the current year to the file name. Last year I managed to create a macro . . . which surprisingly did exactly what was needed, and generated a .pdf file of each worksheet, and saved them to a directory, which I specified.

This year, when I ran the same macro (modified to save the .pdf files to a different directory and to append the current year to the file name), the macro only ran 139 of the worksheets and then stopped with an error.

Run-time error '2147024809 (80070057)':
Expecting object to be local

I tried re-running the macro and the routine truncated at the exact same worksheet again. There doesn't seem to be anything unique or unusual about the 'terminal' worksheet that I can see. This is a puzzle, since the macro seemed to run through and save every worksheet, last year - and very little (of any significance) being changed from last year to this year. I will openly/freely acknowledge that what I know about VBA/macros - you could print on the head of a pin. I can include my very short macro (which I don't have with me today), but I thought I would post this today, to see if there's just some immediately obvious to someone in the listening audience . . . and a fix they would suggest.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
You'll need to post your code. What is better is to remove any confidential data, post the workbook to a download website, then post the link here. Having the workbook is often the fastest way to get an answer.
 
Upvote 0

Forum statistics

Threads
1,226,065
Messages
6,188,678
Members
453,490
Latest member
amru

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