+ Reply to Thread
Results 1 to 4 of 4

quitting worksheet then excel if....

  1. #1
    JNW
    Guest

    quitting worksheet then excel if....

    I have a program used to fill out forms in our department. When logging out
    of the program (commandbutton) I can either close the workbook, or quit the
    application.

    What I would like to know: Is there a way to check to see if there are any
    other workbooks open? If yes then close my program workbook. If no then
    quit excel.

    Thank you

  2. #2
    Rowan Drummond
    Guest

    Re: quitting worksheet then excel if....

    Try something like:

    Sub bks()
    Dim i As Integer
    Dim wkb As Workbook
    For Each wkb In Application.Workbooks
    If wkb.Name <> "PERSONAL.XLS" Then
    i = i + 1
    End If
    Next wkb
    If i > 1 Then
    ThisWorkbook.Close True
    Else
    ThisWorkbook.Save
    Application.Quit
    End If
    End Sub

    Hope this helps
    Rowan

    JNW wrote:
    > I have a program used to fill out forms in our department. When logging out
    > of the program (commandbutton) I can either close the workbook, or quit the
    > application.
    >
    > What I would like to know: Is there a way to check to see if there are any
    > other workbooks open? If yes then close my program workbook. If no then
    > quit excel.
    >
    > Thank you


  3. #3
    JNW
    Guest

    Re: quitting worksheet then excel if....

    Thank you for the reply!

    Because it is one of those days... "Personal.xls" - is this the name of the
    workbook I want to close?

    Thanks again.



    "Rowan Drummond" wrote:

    > Try something like:
    >
    > Sub bks()
    > Dim i As Integer
    > Dim wkb As Workbook
    > For Each wkb In Application.Workbooks
    > If wkb.Name <> "PERSONAL.XLS" Then
    > i = i + 1
    > End If
    > Next wkb
    > If i > 1 Then
    > ThisWorkbook.Close True
    > Else
    > ThisWorkbook.Save
    > Application.Quit
    > End If
    > End Sub
    >
    > Hope this helps
    > Rowan
    >
    > JNW wrote:
    > > I have a program used to fill out forms in our department. When logging out
    > > of the program (commandbutton) I can either close the workbook, or quit the
    > > application.
    > >
    > > What I would like to know: Is there a way to check to see if there are any
    > > other workbooks open? If yes then close my program workbook. If no then
    > > quit excel.
    > >
    > > Thank you

    >


  4. #4
    Rowan Drummond
    Guest

    Re: quitting worksheet then excel if....

    No Personal.xls is a hidden workbook that holds the user's personal
    macros. This book is opened automatically every time Excel starts so if
    you want to check that only one visible workbook is open you should
    exclude Personal.xls from your workbook count.

    Hope this makes sense
    Rowan

    JNW wrote:
    > Thank you for the reply!
    >
    > Because it is one of those days... "Personal.xls" - is this the name of the
    > workbook I want to close?
    >
    > Thanks again.
    >
    >
    >
    > "Rowan Drummond" wrote:
    >
    >
    >>Try something like:
    >>
    >>Sub bks()
    >> Dim i As Integer
    >> Dim wkb As Workbook
    >> For Each wkb In Application.Workbooks
    >> If wkb.Name <> "PERSONAL.XLS" Then
    >> i = i + 1
    >> End If
    >> Next wkb
    >> If i > 1 Then
    >> ThisWorkbook.Close True
    >> Else
    >> ThisWorkbook.Save
    >> Application.Quit
    >> End If
    >>End Sub
    >>
    >>Hope this helps
    >>Rowan
    >>
    >>JNW wrote:
    >>
    >>>I have a program used to fill out forms in our department. When logging out
    >>>of the program (commandbutton) I can either close the workbook, or quit the
    >>>application.
    >>>
    >>>What I would like to know: Is there a way to check to see if there are any
    >>>other workbooks open? If yes then close my program workbook. If no then
    >>>quit excel.
    >>>
    >>>Thank you

    >>


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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