Ozgrid Excel Help & Best Practices Forums


XL Templates | XL Add-ins | XL Training | XL Estimating | XL Scheduling | XL Recovery | XL Trading | XL Financial | XL Conversion | XL Charting


+ Reply to Thread
Results 1 to 3 of 3

Thread: determine if ANY workbook is open before closing down

  1. #1
    Join Date
    3rd August 2004
    Posts
    56

    determine if ANY workbook is open before closing down


    Download Active Data For Excel > > DETAILS > >
    Basically, I have written a VBA app that calls upon Excel, and opens Excel, then opens a workbook, and then makes a few modifications, and then saves and closes that workbook.

    What I cant seem to figure out is how to determine if the user has any other workbooks open before the VBA app attempts to shut down Excel.

    I have found example for a specific workbook, but I will not know what workbook a user night have open. I just want a check tool.

    Thanks for the guidance,
    Dan

  2. #2
    Join Date
    12th January 2005
    Location
    Dusseldorf
    Posts
    232

    Re: determine if ANY workbook is open before closing down

    Hi,

    I'm no expert but i can start you off.

    If you count the number of open workbooks first then build an If function around the numer returned you can say: if there are more than 1 workbooks open then, do something, otherwise close and save changes.

    Thefollowing works but i dont fully understand why itis telling me i have two open when i only have 1 open so i set the value to 2 to show that the logic works.

    Might be my personal macro wk who knows



    Code:
    Sub WORKBOOKS()
    
    nowbs = Application.WORKBOOKS.Count
    
    If nowbs < 2 Then
    
    Application.WORKBOOKS.Close
    
    Else
    
    End If
    
    MsgBox nowbs
    
    End Sub
    Attached Files. REMINDER! OzGrid accepts no responsibility for ANY adverse effects as a result from downloading attached files. ALWAYS run an up-to-date virus scan and disable macros.

  3. #3
    Join Date
    3rd August 2004
    Posts
    56

    Re: determine if ANY workbook is open before closing down


    Create Excel dashboards quickly with Plug-N-Play reports.
    Thanks! That was the lead I needed. I was able to modify it for my needs. I greatly appreciate it, have a great day!
    Dan

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Possible Answers

  1. Function/Formula To Determine If Workbook Open
    By outpatient in forum EXCEL HELP
    Replies: 3
    Last Post: May 16th, 2008, 01:51
  2. Determine If Shared Workbook Open
    By isca in forum EXCEL HELP
    Replies: 2
    Last Post: April 10th, 2008, 06:25
  3. Determine If Workbook Open
    By khenzel in forum EXCEL HELP
    Replies: 2
    Last Post: January 1st, 2008, 03:28
  4. Closing All Open Workbooks
    By Dave Hawley in forum Excel RSS Feed Discussions
    Replies: 0
    Last Post: August 19th, 2007, 15:47
  5. Closing Workbook When Closing Userform
    By pgreene in forum EXCEL HELP
    Replies: 3
    Last Post: September 14th, 2006, 15:52

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