PDA

View Full Version : How to exit print preview mode?



trebla
08-22-2008, 01:51 AM
Hello,

Could some one help me with a problem related to print preview in Excel. I have a macro that ends with the following line:
ActiveWindow.SelectedSheets.PrintPreview

I run this macro from another macro in a separate file like this:
Application.SendKeys "{ESC}"
Application.Run (GA_filename(i) & "!run_specific")

By using sendkeys I try to exit the print preview mode and continue executing the macro. Sometimes this works but most of the time the macro pauses in print preview mode and continues only when I click "Close".

I have no idea why the sendkeys statement works occasionally but not always. Any ideas? Unfortunately, I'm unable to edit the original macro which leads to print preview mode. I have tried to put the sendkeys statement after the running of run_specific macro but it doesn't work that way either. Is there a way to exit print preview mode without using sendkeys statement?

Bob Phillips
08-22-2008, 03:19 AM
Are you sure that the printpreview window has focus ehen you isse the SendKeys?

trebla
08-24-2008, 10:49 PM
Are you sure that the printpreview window has focus ehen you isse the SendKeys?

I'm quite sure about that since the Sendkeys works sometimes. I'm just wondering why it doesn't work always. I have that piece of code inside a loop and last time I tried to run it, the loop was executed successfully 8 times and then on the ninth time it got stuck in the print preview mode and I have no idea why :dunno I have already disabled screen saver, standby mode and all other power saving features that might disturb the Sendkeys method.

trebla
08-25-2008, 11:30 PM
I have that piece of code inside a loop and last time I tried to run it, the loop was executed successfully 8 times and then on the ninth time it got stuck in the print preview mode and I have no idea why :dunno

I investigated this problem again and when the macro gets stuck in the print preview mode, the focus is, in fact, not on the print preview window. I mean that there is another window that is active at the moment when the macro gets stuck. I don't know exactly what this window is, since it only appears in taskbar and disappears when I try to open or see it.

Any one have ideas how to keep the focus on print preview window?