Excel automation: PDF export causes "Printer setup" popup - excel

I am developing an application for automatic Excel to PDF generation. Every now and then (and without any apparent cause, the following popup comes up while the program runs:
Print driver host for 32bit applications stopped working.
and, shortly after, this one:
Printer setup
What, if anything, do I need to do here? My application is not overly complex. The error always (100%) happens on this line:
_application.ActiveWorkbook.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF,
pdfTemplatePath, Excel.XlFixedFormatQuality.xlQualityStandard,
_, _, 1, pdfPrintAreaEnd);
where the variables in question are:
Excel := Microsoft.Office.Intertop.Excel
_application := Excel.Application
_ := System.Type.Missing
pdfPrintAreaEnd := int 6
The exception message is as follows:
System.Runtime.InteropServices.COMException (0x800A03EC):
Exception from HRESULT: 0x800A03EC
What is happening here? And, more importantly: Why is it only happening every one in a while?

Okay, so after some research into this matter, I encountered what I believe is one of the most confuzzling things about Excel automation I have encountered so far.
The error message is consistent with other cases of Excel usage that are both automated and not. The common denominator in all these cases is (buckle up!) that a network printer was set as default printer.
That's right - having a network printer as default, even when you print using a completely different printer or no printer at all (as in the case of exporting to PDF, which is not the same as printing to e.g. Adobe PDF Printer, right?) it will cause this error to sometimes on some machines pop up.
I changed the default printer to something internal, like Microsoft XPS Document Printer, tried again and I can now export hundreds and thousands of PDFs without a single occurrence of the error message.

I had a similar issue on my work laptop. The printer setup would pop-up when trying to execute ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:="\directory\MyFile".
The network printer was set as default. So I navigated to the printer in windows explorer. This prompted me to enter my network password. When I re-ran the code it worked splendidly.(You can find the location of the printer in Windows 10 by typing 'printer' in the windows search bar. Click on Printers And Scanners, navigate to your network printer and then click on manage -> Select Hardware Properties. The location will be displayed next to the image of the printer. In my case the printers location was specified in its name).
In summary, ensure you have access to the default printer. A simple test is trying to print something with your default printer.
If you don't mind changing your default printer follow #F.P solution above.

Someties it,s needed to close your workbook and reopen it.
In my case, when I opened an excel file, it prompted me to click the "Enable Editing" button in the picture below:
When I clicked on it, the excel file wants to open again and Excel splash screen shown again and I closed it immediately. And then I was not to able to save as a PDF both with "Print" button and "VB" code.

Related

What causes this popup in Excel VBA?

I am making a simple tool for my job. It involves opening a file dialog box, selecting a file, opening it, analyzing it for different items, then creating a new workbook with the results. This is all done with VBA macros, activated via a command button.
The code works fine, all does what it's supposed to. However, at the start when the file dialog box is first opened, sometimes this error message pops up:
It doesn't affect the code or how it runs whatsoever, but it is a bit of a nuisance. There is no further detail provided for this "error". Does anyone know what might cause this popup?

Excel VBA Unexpected Error 419 - Permission denied to use object

I have an Excel spreadsheet with VBA programming, form activex controls, form controls. The spreadsheet has worked normally, until last week. I think the problem started when the automatic installation of windows uptade took place, however it might be only coincidence, since I am not positive if this is the cause. Now, the spreadsheet opens and immediately a small window appears that indicates :
“Visual Basic for Applications - Permisson Denied to use object (OK,
Help)”. Selecting help, minimum information and it is irrelevant.
Selecting OK, another window pops out “Visual Basic for Applications -
Unexpected error 419 (OK, Help)”
I cannot even save the sheet to another name. The VBA code cannot run. If I open any new spreadsheet, Excel functions normally, also with its VBA. Just before having this problem, every time that I opened the spreadsheet a window appeared, indicating that Excel blocked the functionalities of the ActiveX controls and asking that if I would allow the use of ActiveX. Today, I enabled all macros and also all activex controls. My previous backups of this spreadsheet have also the same problem. None works. I went to VBA Edit-->References and compared the Libraries I had and the Libraries that are there on the spreadsheet. It seems that no library is missing. How to solve that?
The permissions have changed on your workstation and/or network. Specifically, the folders that hold the DLL files that contain the objects referenced in the VBA. As an example (and I don't know if this is exactly the case, but an illustration), if your code is referencing the Microsoft Scripting Runtime (many VBA projects do), your code needs permissions to access C:\Windows\SysWOW64\scrrun.dll. (I found this by calling up the VBA editor, selecting Tools-->References, then selecting Microsoft Scripting Runtime and reading the bottom of the dialog window for the location.)
This is the location of the DLL on my workstation. Yours might be different or it might have moved during a systems update or the permissions to access that folder may have changed. You'll have to check the locations of all the references in your VBA project to determine this. Sometimes the libraries referenced are located on network drives, which can complicate matters if the network permissions change.
I decided to try to export all the forms (*.frm; *.frx). Everything went fine until I came across to a specific form that had a shockwaveflash object. At this point the message "Permission denied to use object". Bingo!
I then tracked the location on my workstation of such shockwave object reference and applied full administrator control. However, I still could not use shockwave objects. I then uninstalled flash and downloaded the lates shockwaveflash plugin from Adobe. When I open Excel->Developer->Insert->ActiveX Controls->More Controls -> ShockwaveFlashObject and then insert the object in a sheet, the message: "MS Excel - Cannot insert object" appears. I have manually deleted the "*.exd” from C:\Users\[User ID]\AppData\Local\Temp\Excel8.0. Also deleted from C:\Users\[User ID]\AppData\Local\Temp\VBE\, but the problem was still there: "Microsoft Excel - Cannot insert object".
To solve the issue I finally accessed the VBA editor and deleted the userform that had the ShockwaveFlashObject in it. All went back to normal afterwards.

Printing Excel Workbooks on Different Computers

I have an Excel workbook shared with other Excel users. When my co-workers and I use our different computers to print the same sheets to PDF, the page breaks differently in the resulting PDF, even though it displays the same in print preview.
We both run Windows 10, Excel 2016, using the same printer driver and printing preferences. I've confirmed the regional settings in our system are the same. No special fonts are included in the workbook. No difference in the AppData/Roaming/Microsoft/Excel/XLSTART/.
How can I avoid the layout changes? Is there anything that I might have missed checking? Any help would be appreciated!
If you're both printing the same version of the same document on the same printer, driver, operating system, etc, then you are missing a setting.
Some printer settings are buried pretty deep. Also, were you using the Print Preview or Page Preview when you both viewed it?
I suspect you missed a screen of settings somewhere from the image below, likely the Options... button in the bottom right, which take you into the Manufacturer's settings dialog(s).
Another place to check for settings you may have missed is the control pael. Hit the Windows Key and type printers and hit Enter and make sure you double check every setting in that window and all of the sub-dialogs. Some printers can have hundreds of settings.
If you still can't find a difference, get a third person on a different computer to try printing it. The odd man out of the three of your print jobs, is likely the one with the different setting!
If still no go, please post screen shots.
On Windows, Control Panel -> Display settings on different computers distort how Excel fits cells onto a page from computer to computer in my experience.
Windows7 Control Panel Display Settings
Display settings did it for me. I checked language packs, versions, removed and readded the print to pdf driver packs, the works. I was about to clone the working system to the non working system. The non working system had display scaled 125%....

Excel crashes when loading file that contains userform

Excel crashes when opening files that contain a userform
This is a known problem with a known solution workaround which is to delete a file called Excel.box from here:
C:\Users\SlowLearner\Application Data\Microsoft\Forms\Excel.box
According to this forum post the purpose of the Excel.box (& Word.box) file is:
Files such as Winword.box and Excel.box are associated with the
Control Toolbox you see when you are designing a UserForm in the
Visual Basic editor. The files contain information about the layout of
the Control Toolbox (additional tab pages, controls that have been
added or removed, custom icons, ...) If a user has never modified the
Control Toolbox in any way, there will probably be no .box file. By
deleting a .box file, you will restore the Control Toolbox to its
default (factory preset) configuration - this is the only way to do
that. Sometimes, the .box file becomes corrupted and must be deleted.
There are no negative side effects to deleting it.
Unfortunately Excel.box returns :(
It would seem that for most users the problem is fixed by deleting the file, sadly not for me.
I'd like to understand what is causing this problem to recur. A few points to note:
this (touch wood) is not impacting MS Word on my PC
I am using Office 2010, 64 bit version on Win10
I have not made any conscious change to form settings
if I delete the file > start Excel > UN-DELETE the file: everything works :-/
some other experiences with this issue here
For the time being I'll just check for and delete the file before launching Excel, but this is hardly an acceptable solution for the long term. Appreciate thoughts for a proper fix... TIA
Additional Information:
I have not fully explored the crash but so far it happens when:
starting the application by opening an xl?.m file with a userform
application does not get past the splash screen
crashes with the application's CRASH screen (... encounted an error...)
starting the application with a blank worksheet then adding a userform
crashes immediately with the applications CRASH screen displayed (see below)
The above crash happened after rebooting my PC, had a chance to explore it some more.
First I opened the file I had been working on (contains userforms):
annoyingly it opened without crashing
I did NOT enter the IDE
I closed the file (Excel closed normally)
Then I created a new worksheet
I opened the VBA IDE
right-click 'add UserForm' - Excel crashed immediately
(I aborted the recovery / search for a solution attempt)
Then I re-opened the file I had been working on
opened the VBA IDE (the project is PW protected)
the very instant that I entered the PW and hit enter Excel crashed
crash was same both times...
Safe Mode:
Crash still happens in safe mode - steps to reproduce:
Run: Excel /safe
Open VBA IDE
r-click add userform
crashes immediately
Creation of the EXCEL.box file
Based on visually observing the folder which had the Excel.box file I did some tests to try and see when it was created. Basically it seems to appear when one of the following happens:
- the UserForm tools box is closed
- the IDE is closed (after showing the userform)
I've also now tried to modify the userform toolbox by removing everything from it. Excel is still crashing after every restart of the application (which is odd as I was not able to crash it like that earlier).
Office Repair - not tested (yet)
Reluctant to try Office Repair as based on the following quote from here (scroll down: pg 1 reply 8 by Steve IT) I'm not expecting it to work :-/ (but will try if no other suggestions surface).
Thanks for the continued suggestions, however I have tried a repair and also removed Visual Studio 2013 and Office altogether (just in case VS was interfering) and reinstalled both, but it still throws the errors reported previously.
Other user profiles
Created a brand new user called 'test'. Test has the exact same problem.
This problem eventually resolved itself, not sure why. I continued to use Excel normally and it continued to crash so I would delete the offending .box file and start over...
As of Nov 2017 Excel no longer crashes with respect to this issue; my best guess is there was an automatic update that resolved the issue.
Looks like this issue still occurs and it is not just limited to Excel but also Powerpoint.
The fix as mentioned above works where you move / delete any files in the below folder location resolves the issue.
C:\Users\%username%\Application Data\Microsoft\Forms
It is highly likely that this error is caused by bad code in a macro or an Add-In that uses forms. The problem is replicating this can be difficult so you have to debug this in some way when it does crash out.
POWERPNT.box
EXCEL.box
are some of the files that get generated, where Excel or Powerpoint crash on the splash screen.
Try adding the command
ThisWorkbook.VBProject.VBComponents("UserForm").Activate
just before your
"UserForm".Show line.

Enable button using VBA excel

I have an uncommon issue. I have an Excel file with macros. On all computers it was installed Office 2010 and everything worked fine, but a few days ago every computer was upgraded to Office 2013.
In code, at some point I enable or disable some buttons based on some criterias.
ThisWorkbook.Worksheets("Lab Orders").OLEObjects("CommandButton1").Enabled = False
On some computers this works fine , but on other computers this button is shown as enabled, and if the user clicks the button nothing happens, not even the animation where the the button is pressed, so it cannot execute the code behind. It's like an image. Any leads, or reasons why this is happening only on certain computers ?
I have this problem after the Office got upgraded. PS. All computers are in the same domain.
LATER EDIT
I changed the code line
ThisWorkbook.Worksheets("Lab Orders").CommandButton1.Enabled = True
and now I get this error: 438 at this row (I debbuged the file on a computer where this file does not work)
I suspect it's the issue with the latest Office updates - see if this fixes it: http://excelmatters.com/2014/12/10/office-update-breaks-activex-controls/
On all computers where you have the problem, check the box "Trust access to the VBA project object model" located in Options/Trust Center/Macro Settings
(Note that this will only apply to Excel, and if you are having the same problems on other MS Office softwares, you should do the same on them as well)
If that's still not working, read and apply all the checks on this page : https://support.office.com/en-gb/article/Enable-or-disable-macros-in-Office-files-12b036fd-d140-4e74-b45e-16fed1a7e5c6
Did not fit as a comment, so:
If I understand you correctly, some computers show the button enabled, while in fact it is disabled, right?
In this case it's normal no button press animation "visibly happens" as Windows knows the button was programmatically disabled.
The same thing happens if you hook a window (which has buttons on it) and send any button a WM to show itself as if it was enabled (while in fact it is not).
The reason it seems enabled on some computers may vary, most probably it's video card and/or driver 'issue', or some "strange alignment" (that particular OS with that particular graphics card & driver and DirectX, as well as those 'special' OLE settings, etc).In both cases, the screen area don't get "refreshed" (invalidated) after the button was disabled - so it seems enabled and gets "repainted" only when there was some user interaction around it. "Lazy redraw", so to speak :)
What one can do is, if it happens to be a serious issue, to find a way on one of these computers to get the button visibly disabled with some 'workaround' (e.g. changing button text after it was disabled -maybe even to exactly the same text-, or move it 1 pixel away and back, call InvalidateRect on it, etc), and apply that solution to your Excel macro.
UPDATE after reading asker's comment:
Oh I see. This could happen if the buttons are in a control array. The issue in this case, however should be present on all computers... Strange.
Anyway. Try to test the buttons' Index property to see if they are part of a control array, just to be sure. If yes:
a) remove them from the array and create buttons "independent" from each other
b) create a bool array and store there enabled/disabled status and write a function that updates buttons' text color property & handles button click event ignore/accept

Resources