If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Text Boxs

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-02-04, 04:04
allmad allmad is offline
Registered User
 
Join Date: Mar 2004
Posts: 13
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
Reply With Quote
  #2 (permalink)  
Old 05-03-04, 09:19
DavidCoutts DavidCoutts is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 05-03-04, 13:46
allmad allmad is offline
Registered User
 
Join Date: Mar 2004
Posts: 13
Thank you

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

Mark
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On