Consulting

Results 1 to 4 of 4

Thread: How to exit print preview mode?

  1. #1
    VBAX Newbie
    Joined
    Aug 2008
    Posts
    3
    Location

    How to exit print preview mode?

    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?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Are you sure that the printpreview window has focus ehen you isse the SendKeys?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    Aug 2008
    Posts
    3
    Location
    Quote Originally Posted by xld
    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 I have already disabled screen saver, standby mode and all other power saving features that might disturb the Sendkeys method.

  4. #4
    VBAX Newbie
    Joined
    Aug 2008
    Posts
    3
    Location
    Quote Originally Posted by trebla
    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
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •