Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: Workbook problem

  1. #1
    Guest

    Default

    Hello.

    I have a situation

    I have a Macro that loads a form where the user can choose what type of data he wants to load, the just has to click on the appropriate button and the data will be loaded.

    One of the buttons is labelled 'Exit' and what this does is close Excel altogehter.

    I use Application.Quit as the command

    A colleague put a case forward that if the User has the Makro open and he decides to open a standard excel file, and then he chooses to exit the Makro, then both files will close because of the command Application.Quit

    I would like the program to run so that when the Makro is loaded without any additional Excel files being opened and the user clicks on 'Exit' that Excel will close. But if an additional file is already open and the user loads the Makro and then decides to 'Exit' is it possible to check wether there are any Workbooks other than the Makro workbook present ?if so then only do an Activewindow.Close, if not then use the Application.Quit

    Does anybody know how to put that into code?

    I would be grateful for any help you can give.

    Thanks.

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    2,940
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default

    How about this?

    Code:
    If Excel.Workbooks.Count > 1 Then 'More than one workbook open
        ThisWorkbook.Close
    Else
        Application.Quit
    End If
    HTH,
    D

    [ This Message was edited by: dk on 2002-03-07 09:40 ]

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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