Consulting

Results 1 to 4 of 4

Thread: Solved: Close all but Activesheet

  1. #1
    VBAX Regular
    Joined
    Jul 2008
    Posts
    43
    Location

    Solved: Close all but Activesheet

    Still searching for a way to close second date that macro seems to got to and read this

    [VBA]Option Explicit
    Sub CloseAllExceptActive_NoSave()
    With Application
    .ScreenUpdating = False
    'Loop Through open documents
    Do Until .Documents.Count = 1
    'Close no save
    .Documents(1).Close SaveChanges:=wdDoNotSaveChanges
    Loop
    .ScreenUpdating = True
    End With
    End Sub
    [/VBA]
    The question it came from was about word. Can I just change "Documents" to "Workbooks" to make it work in excel ? Or do I need to alter it at all?
    Last edited by mdmackillop; 07-26-2008 at 06:45 AM. Reason: Missed VBA bracket

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub CloseAllExceptActive_NoSave()
    Dim wb As Workbook

    With Application

    .ScreenUpdating = False
    For Each wb In .Workbooks

    If wb.Name <> ActiveWorkbook.Name Then

    wb.Close savechanges:=False
    End If
    Next wb

    .ScreenUpdating = True
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Jul 2008
    Posts
    43
    Location
    Thank you
    One other question I now want the active workbook to save its changes
    so after this sub has run I can put in the code
    [VBA]Activeworkbook.save[/VBA]

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You can run that at any time, before or after closing the other workbooks
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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