I've been a longtime lurker and am now a first time poster! I hope this isn't the case, but it looks like it may be a bug on Microsoft's side of things.
I have a relatively simple macro that is run on the BeforeClose and BeforePrint conditions. The sub's purpose is to print a pdf to a networked location with a time stamp.
Everything works great as long as the macro is not called in the BeforePrint event. Here is the code:
Now, this instance works fine...![]()
Please Login or Register to view this content.
But if I put the call to exportPDF in there, it throws up an error or crashes depending on if I have the error handler on.![]()
Please Login or Register to view this content.
Edit: This code seems to "activate" even when the sub of BeforePrint shouldn't even be invoked. It crashes even when I simply try to close the file. The exact same code is invoked at the BeforeClose sub, and it causes no problems there.
Moderator's note: Moved to other forum to get better exposure for this specific problem --6SJ
Ok, I fixed the issue. The desired end result was a time stamped PDF in the same directory as the Excel file. I also wanted this file saved every time the worksheet was closed and/or printed. This was achieved by the Me.Save call in the BeforeClose and BeforePrint subs. I was trying to also call the exportPDF sub I previously defined in the BeforeClose and BeforePrint subs. This is where the error was invoked. The solution was to call the exportPDF sub in the AfterSave sub.
This is my fully functional code:
Thank you to everyone that looked at this. I hope this helps someone else in the future.![]()
Please Login or Register to view this content.
Bookmarks