Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004
    Posts
    13

    Unanswered: Closeing an excel sheet in VB

    Just a little one ( so the wife says )

    Im tring to close an excel sheet from a differant work book, this I can do.

    Private Sub CommandButton7_Click()
    Windows("Week One.xls").Activate
    ActiveWindow.Close
    End Sub

    Problem is if ("week One") is already shut. I get that nasty error

    Please if anyone can help

  2. #2
    Join Date
    Oct 2003
    Posts
    1,091
    Perhap modify this IF statement:

    Code:
    Dim Book As Workbook
    For Each Book In Workbooks
       If Book.Name <> ThisWorkbook.Name Then
          Book.Close savechanges:=True
       End If
    Next Book
    old, slow, and confused
    but at least I'm inconsistent!

    Rich
    (retired Excel 2003 user, 3/28/2008)

    How to ask a question on forums

  3. #3
    Join Date
    Mar 2004
    Posts
    13

    Thanks

    That works lovley thanks a lot

    Maybe you can help with another problem

    When I right comething in vb it put the link in from were the file is

    ie
    __________________________________________________ _____________
    Private Sub CommandButton1_Click()
    ChDir "C:\Documents and Settings\Mad1\Desktop\New Folder"
    Workbooks.Open Filename:= _
    "C:\Documents and Settings\Mad1\Desktop\New Folder\Week One.xls"
    Sheets("Home W1").Select
    End Sub
    __________________________________________________ _____________

    how can I put this onto another PC so it doesnt look for my PC, it just looks in the folder were the files are

    Mark

Posting Permissions

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