+ Reply to Thread
Results 1 to 7 of 7

Control closing file - elegantly

  1. #1
    Registered User
    Join Date
    03-10-2013
    Location
    N/A
    MS-Off Ver
    Excel 2010
    Posts
    62

    Control closing file - elegantly

    Hi All:

    Please consider the following code:

    Please Login or Register  to view this content.
    The above code is in the thisworkbook module.

    I'm opening a workbook from a shortcut. It does some processing and then closes itself.

    What I'm trying to do is to leave things as they were before execution. So if excel was already open, I want to leave it that way. The problem is that after the above runs, the excel that was running is invisible, so that when the user clicks the Excel icon, she gets a message "'personal.xlsb' is locked", which means that the system is bringing up a new instance of Excel.

    I also want to ensure that if excel was running in a visible window in part of the screen, that it stays that way after execution.

    Can you help me?

    Thanks,

    Yossi

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    8,775

    Re: Control closing file - elegantly

    Make it Visible and ScreenUpdate before closing so that part of the code can execute.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    03-10-2013
    Location
    N/A
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Control closing file - elegantly

    Thanks!

    We're almost there.

    The code unminimizes the window.

    How can I control that it should retain its original minimized/maximized state?

    Thanks,

    Yossi

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    8,775

    Re: Control closing file - elegantly

    Quote Originally Posted by yossel View Post
    Thanks!

    We're almost there.

    The code unminimizes the window.

    How can I control that it should retain its original minimized/maximized state?

    Thanks,

    Yossi

    That's problematic. When you open the workbook, the application window maximizes before any code is run. The Workbook_Open code doesn't have a chance to determine the window state prior to opening the workbook.

    You could have the Workbook_Open macro always set the window state to min or max, but I don't know of a way for it to determine the previous windows state prior to opening.

    FYI: Application.WindowState will read or write the windows state

  5. #5
    Registered User
    Join Date
    03-10-2013
    Location
    N/A
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Control closing file - elegantly

    Ok, thanks.

    However, the following code makes the system unminimize the application window back to Normal or Maximized, whatever the state was before it was minimized. How do I unconditionally minimize it, period?

    Please Login or Register  to view this content.

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    8,775

    Re: Control closing file - elegantly

    Again, do it before you close the workbook otherwise the code after you close the workbook doesn't execute.

  7. #7
    Registered User
    Join Date
    03-10-2013
    Location
    N/A
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Control closing file - elegantly

    Of course! <gnashing of the teeth>

    Thanks so much for your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1