Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check Workbooks Open

Status
Not open for further replies.

DanMan1

Programmer
Dec 3, 2004
8
GB
Hi,

Would any know a way to check how many workbooks are open in an excel session??

Any help would be appreciated.

Cheers

Dan
 
Hi DanMan1,

Try ..

[blue][tt] Application.Workbooks.Count[/tt][/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
I need to so somthimg similar to the above thread. Only I need to check for a specific workbook and if the specific workbook exists then a MsgBox will return "You already have a document with the same name open. The document will be a dynamic name based on three ComboBoxes and a TextBox.

This is what I tried, but it doesnt work. =(

Code:
If Application.Workbooks = ("Q:\elogs\newformat\" & Me.ComboBox1.Value & "\" & "elog_" & Me.ComboBox1.Value & "_" & Me.ComboBox2.Value & "." & Me.ComboBox3.Value & "." & Me.TextBox1.Value & ".xls") Then
MsgBox "You already have a document of the same name open"
End If
Exit Sub
 
Hi,

You could use
If Len(Dir(strPath & strFile))>0 then
'Do somthing
End if
This would tell you if a file exists

Or you could use
Dim wbk As Workbook

For Each wbk In Application.Workbooks
If wbk.Name = ("Q:\elogs\newformat\" & Me.ComboBox1.Value & "\" & _
"elog_" & Me.ComboBox1.Value & "_" & Me.ComboBox2.Value & "." & _
Me.ComboBox3.Value & "." & Me.TextBox1.Value & ".xls") Then
MsgBox "You already have a document of the same name open"
End If
Next

'This will go through each workbook in the active application and if name matchs criterea the msgbox will open.


HTH

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top