Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default code to open another workbook

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default code to open another workbook

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

--
Garry

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default code to open another workbook

GS pretended :
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("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.

--
Garry

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default code to open another workbook

On Apr 29, 7:46*pm, GS wrote:
GS pretended :





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("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.

--
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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
code to open another workbook Rob[_34_] Excel Programming 0 April 30th 11 03:29 AM
code to open another workbook Rob[_34_] Excel Programming 0 April 30th 11 03:29 AM
Need VB code for workbook open to open a link Daniel Baker Excel Discussion (Misc queries) 2 August 18th 06 01:30 AM
Code to open new workbook Andrew[_27_] Excel Programming 3 January 22nd 04 01:24 PM
Workbook Open code Chip Pearson Excel Programming 0 August 1st 03 05:29 PM


All times are GMT +1. The time now is 10:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"