excel vba bug with Application.GetSaveAsFilename or Application.Dialogs(xlDialogPrinterSetup) - excel

first time posting but have learned so much in this place already! Now there's an issue for which i do not find a way out..
I have an excel sheet with a bunch of userforms which is used for invoicing. In one of the userforms, the user has the possibility to print the invoices.
All code runs fine up to the line:
fname = Application.GetSaveAsFilename("", "PDF Files (*.pdf), *.pdf")
Then the computer freezes, and Microsoft Excel is apparently using >60% of the processor capacities. After many minutes the "save as" window finally pops open, and all works perfectly again.
I've tried going around this issue and printing to pdf instead of saving to pdf, but the same happens on the line:
If Application.Dialogs(xlDialogPrinterSetup).Show = True Then
ActiveWindow.ActiveSheet.PrintOut
End If
Is there any known issue with this code on weaker computers? All code works fine on my computer, but not on the user's pc.
I've built in stops, and msgboxes on the other parts of the code, just in case the issue would be elsewhere, but it's really only on these lines that the computer panics.
Thanks a lot in advance for any advice!

Related

Excel hangs/crashes while updating external link at file opening

I encountered this weird ass and funny error.
I built a file for data ETL. This one takes in various .csv files, combines them and export new .csv files using VBA. The file is originally named as "xxx Modelling ETL.xlsm". It could be opened normally till one day it hangs or crashes while trying to recalculating something (may be the underground query).
After hours of struggling, I opened the file as a copy (under a new name of Copy of ...). Strangely it ran smoothly, no crash or hang. Then I try rename it by remove the "Copy of" part, then the error occurs again.
I want to share this as there could be someone has the same problem, or someone who could shed some light on this black magic thing.
Some solutions:
Rename the file or move it to local drive instead of Onedrive makes thing works normally again.
Open Trust Center, disable Macro with notification, Trusted Locations, and Trusted Documents. Enable them for specific files when open, not for all.

Strange problem with workbooks.open in VBA

Problem with VBA - workbooks.open. I can't open two files simultaneously.
Hi,
Maybe it's simply the way it's supposed to be, but it seems strange to me. My macro works fine as long as I open only one file in the background using workbooks.open. But when I'm opening the second file, then the first one just closes. Is it normal?
Nothing very complicated. First i Open database:
Set database = Workbooks.Open(Filename:="Y:\EME\LW\PL-PIA\AIR\AIRFREIGHT\Zlecenia transportowe\baza_danych_transp.xlsm", ReadOnly:=True)
Then, when I open CMR, the database switches off.
Set CMR = Workbooks.Open("Y:\EME\LW\PL-PIA\AIR\AIRFREIGHT\Zlecenia transportowe\CMR_bis.xlsm")
Do I need to create a new instance of excel application for this?
I'm sorry, but I think I know what was causing the problem... I had a macro embedded in CMR that on opening of the workbook was getting some data from database and then was closing it. I dead forgot about it... Thanks for help, switching the names of the worbooks did remind me about it...

DOORS DXL Export to .xlsx unreadable...except in Word

I have a DOORS DXL script that (used to) export data to an Excel worksheet. It uses the filename specified/chosen through a GUI and tacks ".xlsx" on the end.
Well, the file is created and written to by the application. You cannot, however, open it with Excel, as the application complains
that "Excel cannot open the file 'Output.xlsx' because the file format or file extension is invalid." You can open it with Word 2016
and the text is totally readable. (??!!!)
This script was last used/modified in 2011. I believe the DOORS version was 9.1 on that project. Is that a contributing factor? (Using DOORS 9.6 on current project)
Anyone have any idea what debug steps I should take?
Thanks,
T Wilk
I tried exporting to .xls, and it worked, sort of... I had other problems to work through, so maybe if I went back and tried it again, now that those are solved, it would be fine.
Found out some interesting stuff today. I changed the 'file create' extension to .tsv, made my delimiter "\t", and the export worked beautifully. And .tsv files can easily be saved as .xlsx. Don't know what changed between DXL and Excel since the last time I used them together, but the straight export to .xlsx is not an option.
I also learned, since the last time I did this sort of thing, i.e., DOORS to Excel, that API's have been created so that you don't have to bother with setting up the
export in your code. Someone pointed me to some Mike Sunderland code (Galactic Solutions). I'm going to pick that apart tomorrow.
Got a lot to do, and I'm having fun!
Thanks for the time and interest.
Tara

excel 2010 how to close password protected file with other files open?

I've got a pw protected excel 2010 file. I can only close it when there are no other excel files open. Also in the sub window for the file, no "x" is present. Since I normally have 5 or more files open, closing it down does mean I close all the other files, close the pw file and open the others again. I'm sure there's a simpler way, but I just can not find it.
Stupid litte question, but when I try to google it all that turns up are a thousand ways to crack password protected files. Thats not what I need.
Any help is much appreciated,
Arnold

Run-time Error '1004' - Method 'Open' of object 'Workbooks' failed

OK, so far I've uninstalled & re installed Office-2010 3 to 4 times, done hours of research for 3 days with no success. I started getting this error either from Vbscript or Excel VBA, performing the same command that has worked for months. I am not sure what I may have changed, I don't recall changing anything that could cause it but I nailed it down to the ReadOnly:=True parameter. I think something may be wrong with the registry... but re-installing should fix it right? It didn't...
Anyways, very simple command that I recorded on Excel 2010. This command WORKS FINE and the file opens:
Sub Macro1()
Workbooks.Open Filename:="C:\temp\file_9928_131101.xlsx"
End Sub
But when I add the ReadOnly:=True parameter, it does NOT WORK:
Sub Macro1()
Workbooks.Open Filename:="C:\temp\file_9928_131101.xlsx", ReadOnly:=True
End Sub
This is the returned error Run-time error '1004' Method 'Open' of object 'Workbooks' failed:
When I click Debug, the error is at the only line of code.
The file is corrupted. Resave it with another name and change the name in the function. Try that it works and after that rename the file as you want to call it.
It worked for me and I had a corrupted file. The read only shouldn't be a problem.
Putting an answer here for others like myself who have this issue and the normal solutions don't work.
Another potential cause of this is corrupted temporary files. I think it may only apply if the file you are trying to open is on a network drive or other remote host.
Anyway, try wiping your temp folder (as in the one you get to if you type %temp% into Windows Explorer) then restarting the computer.
I have had the same issue with an Access file stored in a local OneDrive folder, referencing an Excel file stored in the same local OneDrive folder. The solution was to move all files into a "static" (i.e., not synchronized, not OneDrive) folder.
Thought that this specific case/application might help someone.
I realise this is late but if you want to open & repair a corrupted workbook automatically use:
Set oWB = Workbooks.Open(Filename:="C:\my\file\path.xlsx", CorruptLoad:=XlCorruptLoad.xlRepairFile)
If you are downloading the file from some external source (eg- email), just open the file directly from the email and then save the file. Try opening the file in macro ...hope it works...it worked for me....:)
I had a rogue excel process that was running in the background. When I killed it from the task manager the code worked. I hope this helps.
I was too, going crazy with Workbook.Open function, getting the weird Open fail error for no obvious reason. My code also did some some copy-pasting after Open function, which seemed to trigger it.
Eventually I found out that turning ScreenUpdating OFF seemed to cause this - keeping ScreenUpdating ON, made things click for me (maybe someone finds this helpful in the future). I'm one of those who tends to switch ScreenUpdating off for all code whenever possible.
Application.ScreenUpdating = False
I know I'm answering late on this, but I resolved a similar issue (same error but running excel from a .Net app) by making sure VBA was installed correctly on the target machine.
Control Panel->Programs and Features->Uninstall a Program... find your Office install, Right-click and select "change" ->Add Remove Features->Office Shared Features->Visual Basic for Applications->Run From My Computer
This did it for me.

Resources