code to open another workbook

R

Rob

I am building an application in one workbook that requires another
workbook be open. Here is the code I am using:

Private Sub OB1_Click()
Workbooks.Open Filename:="C:\Data1.xlsx"
UF1.Hide
End Sub

This does the job, but what is the code that determines if this
workbook "C:\Data1.xlsx" is already open so it doesn't try and re-open
it?

Thank you,

Rob
 
G

GS

Rob submitted this idea :
I am building an application in one workbook that requires another
workbook be open. Here is the code I am using:

Private Sub OB1_Click()
Workbooks.Open Filename:="C:\Data1.xlsx"
UF1.Hide
End Sub

This does the job, but what is the code that determines if this
workbook "C:\Data1.xlsx" is already open so it doesn't try and re-open
it?

Thank you,

Rob

Here's a generic function that you can reuse in any project:

Function bBookIsOpen(wbkName) As Boolean
' Checks if a specified workbook is open.
' Arguments: wbkName The name of the workbook
' Returns: True if the workbook is open

Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbkName)
bBookIsOpen = (Err = 0)
End Function

To use it...

Private Sub OB1_Click()
If Not bBookIsOpen("C:\Data1.xlsx") Then _
Workbooks.Open Filename:="C:\Data1.xlsx"
UF1.Hide
End Sub
 
G

GS

GS pretended :
Rob submitted this idea :

Here's a generic function that you can reuse in any project:

Function bBookIsOpen(wbkName) As Boolean
' Checks if a specified workbook is open.
' Arguments: wbkName The name of the workbook
' Returns: True if the workbook is open

Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbkName)
bBookIsOpen = (Err = 0)
End Function

To use it...

Private Sub OB1_Click()

If Not bBookIsOpen("Data1.xlsx") Then _
Workbooks.Open Filename:="C:\Data1.xlsx"
UF1.Hide
End Sub

Sorry, bad copy/paste! Make the correction to the above revised line.
 
R

Rob

GS pretended :











   If Not bBookIsOpen("Data1.xlsx") Then _


Sorry, bad copy/paste! Make the correction to the above revised line.

--
Garry

Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc

Thanks Garry, I'll give this a try

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top