Results 1 to 11 of 11
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Flims, Switzerland
    Posts
    271
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I close a Print Preview window from code? (97)

    I've tried various methods, like SendKeys and activating the workbook
    windows, etc. but nothing seems to work. The Print Preview window
    seems to be some kind of modal dialog. I'm thinking if I can get the
    hwnd of the dialog then I can use the API to close it. But I don't
    know how to get the hwnd. Does anyone know what the Window Style and
    caption of the Print preview window is? I could then use FindWindow.
    Thanks,

    Adam Ralph

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: How do I close a Print Preview window from code? (97)

    The actual Print Preview window does not seem to have a caption, but has a class name of Excel@ if that is of any help.

    Just curious, but why not let the user close it when they have finished previewing ?

    Andrew

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Flims, Switzerland
    Posts
    271
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do I close a Print Preview window from code? (97)

    Thanks Andrew, I'll experiment with Excel@ and see if I can get it to work. Out of curiosity, how did you find that out?
    With regard to your quesion about letting the user close the preview, I hear what you are saying, but I'm actually trying to solve this for another programmer, who seems to spawn an Excel.Application from code, and then needs to kill Print Preview _if_ a user has switched to print preview mode in that instance of the application.

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: How do I close a Print Preview window from code? (97)

    How did I find out ?. Check <A target="_blank" HREF=http://www.wopr.com/cgi-bin/w3t/showflat.pl?Cat=&Board=vb&Number=50137&page=&view= &sb=&o=&vc=1>This Thread</A>. There is some code for getting at Class names posted there, but not suitable for Office 97. However I am attaching a VB version compiled to a standalone EXE (zipped), which you can experiment with.

    It is not very sophisticated, but it shows the class name of the window under the mouse pointer.

    Andrew
    Attached Files Attached Files

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Flims, Switzerland
    Posts
    271
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do I close a Print Preview window from code? (97)

    Andrew, thanks for the thread. I also have VB so I ran the code from there. I also added a call to GetWindowText to find out the caption. It appears that the Excel@ window has NO caption.
    In fact, I'm beginning to think that this method is not going to work. I don't think I can just kill the Window since the normal user action is a button press outside the window, and besides, using FindWindow, passing Excel@ as the classname seems risky as it might yield the hwnd of another print preview window somewhere else.

  6. #6
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: How do I close a Print Preview window from code? (97)

    If it has no name, can you not tell it to close any window where the name is empty? Just a suggestion.

    Although this would risk closing other preview windows, as you say.
    Beryl M


  7. #7
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Flims, Switzerland
    Posts
    271
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do I close a Print Preview window from code? (97)

    that would not only risk closing other print previews, but also other windows which also have no text. I can't see the benefit if I already know that the WindowClass is Excel@

  8. #8
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: How do I close a Print Preview window from code? (97)

    Could you get a handle on all the child windows of the main applcation (in this case Excel), and then close the one with class name EXCEL@ (EXCELB, if I recall in XL 2000). I cannot imagine 2 print previews at the same time in the one application.

    I thought the code included GetWindowText to provide the caption where applicable.

    Andrew

  9. #9
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do I close a Print Preview window from code? (97)

    This might be totally useless, but just in case.

    Would it help if you disabbled Print Preview for that particular application?

    Or perhaps you could intercept it, and set a value in a hidden worksheet? When it's time for your code, check that value? (Though I'm not quite sure how to reset the value when the window is closed).

    Sorry, just trying a little lateral thinking here.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  10. #10
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Flims, Switzerland
    Posts
    271
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do I close a Print Preview window from code? (97)

    I'm trying to solve this problem for another programmer, and I don't believe disabling print preview is an option for him, I believe print preview still needs to be allowable. As for setting a hidden value, I can't see how that can help in closing the print preview window from code, could you perhaps expand?

  11. #11
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Flims, Switzerland
    Posts
    271
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do I close a Print Preview window from code? (97)

    yes, I think you're right, I should get a child window of the Application which is Excel@ and try and close that. Whether I can actually do that, or whether I have so simulate the 'Close' button click is another question.

Posting Permissions

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