Results 1 to 2 of 2

Thread: Save and Close all workbooks in Excel 97

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2003
    Location
    Mt. Holly, NJ
    Posts
    31

    Save and Close all workbooks in Excel 97

    Hi all,

    I want to create a loop that saves each workbook in Excel 97 and then closes them. Preferably it would look like

    Do until ActiveWorkbooks = "" 'Or whatever the code for this is

    ActiveWorkbook.Save
    ActiveWorkbook.Close

    Loop

    The piece of code that I really need is the first bit, the Do Until part. Not really sure how to know that all of the workbooks have been dealt with.


    Thanks
    Last edited by Yesuslave; Jul 16th, 2022 at 07:20 AM.

  2. #2
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    There is only one "active" workbook. You are looking for the Workbooks property. The VBA help file Workbooks Property Example gives an example of almost exactly what you are aking for. Like this:

    VB Code:
    1. Dim w As Workbook
    2. For Each w In Workbooks
    3.     w.Close savechanges:=True
    4. Next w

Posting Permissions

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



Click Here to Expand Forum to Full Width