Results 1 to 3 of 3

Thread: Text Boxs

  1. #1
    Join Date
    Mar 2004
    Posts
    13

    Unanswered: Text Boxs

    Would like some help with this please

    Trying to close a work book and if its all ready close I want a text box to come up with "WEEK ONE ALREADY CLOSED" the you click ok and it shuts

    The code so far is as follows

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

    Thanks

    Mark

  2. #2
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067

    Close Workbook

    Hi Mark
    If you change your code to something like this

    Code:
        Dim wkbook As Workbook
        
        For Each wkbook In Application.Workbooks
            If wkbook.Name = "Week One.xls" Then
                'If Workbook Week One.xls is open shut it and
                'Leave Routine
                wkbook.Close
                Exit Sub
            End If
        Next wkbook
        'Display Messagebox as workbook not found
        MsgBox "Workbook not Found"
    this code looks at all open workbooks and if one of them is called
    "Week One.xls" then it closes it and leaves the subroutine
    otherwise a messagebox pops up to say that the workbook is not open

    HTH

    David

  3. #3
    Join Date
    Mar 2004
    Posts
    13

    Thank you

    Thank you David thats just what I was looking for....

    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
  •