ExportAsFixedFormat Error

Murf

New Member
Joined
Apr 22, 2009
Messages
25
I have an 2007 Access database that pull data from an AS/400 and saves the data in excel. I just added the option to save the excel file as a PDF instead of excel. This code works the first time. But the second report gets the error. If I compact and repair the same report that caused the error works but the next one doesn't. Any Ideas?

Code:
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, FileName:=strSaveAs, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

Error:
91 - Object variable or With block variable not set

strSaveAs = "j:\XLS\FileName.PDF"
xlTypePDF = 0
xlQualityStandard = 0
 
Last edited:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
The problem is that you are using

ActiveWorkbook...

And not fully qualifying it. Activeworkbook should be tied to an Excel Application Object and not by itself. So something like:

objXL.Activeworkbook

if you have created an object named objXL as the application object.

If you don't then Activeworkbook will create an Excel object in the background, but the only way to get rid of it is to either exit the Access database or use Task Manager to kill the Excel instance.
 
Upvote 0
Thanks Bob. That did the trick.
GladWeCouldHelp.png
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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