Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default Is Workbook open without error

Hi! I have a macro that sometimes opens another workbook. However sometimes
that workbook is already open. In that case I do not want to reopen it. I
have a UDF that checks if the workbook in fact is open but the problem is
that I get Error 9. Is there any way to check if the workbook is open and not
get an error? (this error ruins the rest of my program..). strFXOptionPath is
a string that contains the name of the workbook.

If WorkbookIsOpen(strFXOptionPath) = False Then
........

Private Function WorkbookIsOpen(wbname) As Boolean
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbname)
If Err = 0 Then WorkbookIsOpen = True _
Else: WorkbookIsOpen = False
End Function


Any help appreciated!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Is Workbook open without error

You should pass just the workbook name to that routine, not the path as
well.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Arne Hegefors" wrote in message
...
Hi! I have a macro that sometimes opens another workbook. However
sometimes
that workbook is already open. In that case I do not want to reopen it. I
have a UDF that checks if the workbook in fact is open but the problem is
that I get Error 9. Is there any way to check if the workbook is open and
not
get an error? (this error ruins the rest of my program..). strFXOptionPath
is
a string that contains the name of the workbook.

If WorkbookIsOpen(strFXOptionPath) = False Then
.......

Private Function WorkbookIsOpen(wbname) As Boolean
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbname)
If Err = 0 Then WorkbookIsOpen = True _
Else: WorkbookIsOpen = False
End Function


Any help appreciated!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default Is Workbook open without error

Hi Bob! Thanks for your answer! I dont pass the path, although it might look
like that. Like I said strFXOptionPath is a string the contains the NAME of
the workbook not the path. However that has nothing to do with the error. The
error comes from:
Set x = Workbooks(wbname). If Err=0 then it is open and if Err<0 then it
is not open. As the code suggest that line produces an error. Now this error
is not a problem at that particular place but it gets to be a problem later.
therefore i wonder if there is any way of checking if the book is open
without producing an error in case it is not open. Would very much appreciate
help with this! Thanks alot!

"Bob Phillips" skrev:

You should pass just the workbook name to that routine, not the path as
well.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Arne Hegefors" wrote in message
...
Hi! I have a macro that sometimes opens another workbook. However
sometimes
that workbook is already open. In that case I do not want to reopen it. I
have a UDF that checks if the workbook in fact is open but the problem is
that I get Error 9. Is there any way to check if the workbook is open and
not
get an error? (this error ruins the rest of my program..). strFXOptionPath
is
a string that contains the name of the workbook.

If WorkbookIsOpen(strFXOptionPath) = False Then
.......

Private Function WorkbookIsOpen(wbname) As Boolean
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbname)
If Err = 0 Then WorkbookIsOpen = True _
Else: WorkbookIsOpen = False
End Function


Any help appreciated!




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default Is Workbook open without error

Should you disable error handling in the function ?

Private Function WorkbookIsOpen(wbname) As Boolean
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbname)
If Err = 0 Then WorkbookIsOpen = True _
Else: WorkbookIsOpen = False

On Error GoTo 0

End Function


--

Regards,
Nigel




"Arne Hegefors" wrote in message
...
Hi Bob! Thanks for your answer! I dont pass the path, although it might
look
like that. Like I said strFXOptionPath is a string the contains the NAME
of
the workbook not the path. However that has nothing to do with the error.
The
error comes from:
Set x = Workbooks(wbname). If Err=0 then it is open and if Err<0 then it
is not open. As the code suggest that line produces an error. Now this
error
is not a problem at that particular place but it gets to be a problem
later.
therefore i wonder if there is any way of checking if the book is open
without producing an error in case it is not open. Would very much
appreciate
help with this! Thanks alot!

"Bob Phillips" skrev:

You should pass just the workbook name to that routine, not the path as
well.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"Arne Hegefors" wrote in message
...
Hi! I have a macro that sometimes opens another workbook. However
sometimes
that workbook is already open. In that case I do not want to reopen it.
I
have a UDF that checks if the workbook in fact is open but the problem
is
that I get Error 9. Is there any way to check if the workbook is open
and
not
get an error? (this error ruins the rest of my program..).
strFXOptionPath
is
a string that contains the name of the workbook.

If WorkbookIsOpen(strFXOptionPath) = False Then
.......

Private Function WorkbookIsOpen(wbname) As Boolean
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbname)
If Err = 0 Then WorkbookIsOpen = True _
Else: WorkbookIsOpen = False
End Function


Any help appreciated!





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
Error Message when I open Workbook Mouimet Excel Worksheet Functions 2 November 10th 09 07:19 PM
Macro error when trying to open workbook paankadu Excel Worksheet Functions 6 November 6th 09 03:54 PM
Open Workbook error alexrs2k Excel Discussion (Misc queries) 3 September 17th 09 07:40 PM
Error on activating a window a open workbook Hari[_3_] Excel Programming 1 June 11th 04 12:58 AM
Error when Open WorkBook tetors_2002[_5_] Excel Programming 1 May 17th 04 06:10 PM


All times are GMT +1. The time now is 02:58 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"