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

i've seen almost identical code in a few place, but it doesn't work, the
variable always evaluates to nothing. why? i just need to test if the other
workbook is open and if not, open it.

Dim WBook As Workbook
'...
On Error Resume Next
Set WBook = Workbooks("Workbook2")
On Error GoTo 0
If WBook Is Nothing Then
'your sorting code
End If


--


Gary



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default testing for open workbook

Try

Set WBook = Workbooks("Workbook2.xls")

Regards
Rowan

Gary Keramidas wrote:
i've seen almost identical code in a few place, but it doesn't work, the
variable always evaluates to nothing. why? i just need to test if the other
workbook is open and if not, open it.

Dim WBook As Workbook
'...
On Error Resume Next
Set WBook = Workbooks("Workbook2")
On Error GoTo 0
If WBook Is Nothing Then
'your sorting code
End If


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default testing for open workbook

i've put the whole name in there and it didn't make any difference

--


Gary


"Rowan" wrote in message
...
Try

Set WBook = Workbooks("Workbook2.xls")

Regards
Rowan

Gary Keramidas wrote:
i've seen almost identical code in a few place, but it doesn't work, the
variable always evaluates to nothing. why? i just need to test if the
other workbook is open and if not, open it.

Dim WBook As Workbook
'...
On Error Resume Next
Set WBook = Workbooks("Workbook2")
On Error GoTo 0
If WBook Is Nothing Then
'your sorting code
End If


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default testing for open workbook

this seems to work for what i need

On Error GoTo OpenFile
Windows("workbook.xls").Activate
GoTo CopyRoutine

OpenFile:
'open the workbook

CopyRoutine
' do my copy routine



it if isn't open, it won't activate.
--


Gary


"Rowan" wrote in message
...
Try

Set WBook = Workbooks("Workbook2.xls")

Regards
Rowan

Gary Keramidas wrote:
i've seen almost identical code in a few place, but it doesn't work, the
variable always evaluates to nothing. why? i just need to test if the
other workbook is open and if not, open it.

Dim WBook As Workbook
'...
On Error Resume Next
Set WBook = Workbooks("Workbook2")
On Error GoTo 0
If WBook Is Nothing Then
'your sorting code
End If


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default testing for open workbook

Gary,
You're testing whether "Workbook2" is open in the current instance of Excel.
If it is not, the WBook will be Nothing.

What I think you mean is "Is Workbook2 already opened by somebody else ?
For that you have to try and open it:
Set WBook = Workbooks.Open (..argument..)

You may want to check out .DisplayAlerts also.

NickHK

"Gary Keramidas" wrote in message
...
i've seen almost identical code in a few place, but it doesn't work, the
variable always evaluates to nothing. why? i just need to test if the

other
workbook is open and if not, open it.

Dim WBook As Workbook
'...
On Error Resume Next
Set WBook = Workbooks("Workbook2")
On Error GoTo 0
If WBook Is Nothing Then
'your sorting code
End If


--


Gary







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default testing for open workbook

not for somebody else, only me. i have both workbooks open in one instance
of excel. both workbooks appear under the window menu. the variable always
evaluates to nothing.

don't know why it won't work.
--


Gary


"NickHK" wrote in message
...
Gary,
You're testing whether "Workbook2" is open in the current instance of
Excel.
If it is not, the WBook will be Nothing.

What I think you mean is "Is Workbook2 already opened by somebody else ?
For that you have to try and open it:
Set WBook = Workbooks.Open (..argument..)

You may want to check out .DisplayAlerts also.

NickHK

"Gary Keramidas" wrote in message
...
i've seen almost identical code in a few place, but it doesn't work, the
variable always evaluates to nothing. why? i just need to test if the

other
workbook is open and if not, open it.

Dim WBook As Workbook
'...
On Error Resume Next
Set WBook = Workbooks("Workbook2")
On Error GoTo 0
If WBook Is Nothing Then
'your sorting code
End If


--


Gary







  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default testing for open workbook

Gary,
It does work if there is a WB called that name.
Comment out the "On Error.. and see what error is being raised.

NickHK

"Gary Keramidas" wrote in message
...
not for somebody else, only me. i have both workbooks open in one instance
of excel. both workbooks appear under the window menu. the variable always
evaluates to nothing.

don't know why it won't work.
--


Gary


"NickHK" wrote in message
...
Gary,
You're testing whether "Workbook2" is open in the current instance of
Excel.
If it is not, the WBook will be Nothing.

What I think you mean is "Is Workbook2 already opened by somebody else ?
For that you have to try and open it:
Set WBook = Workbooks.Open (..argument..)

You may want to check out .DisplayAlerts also.

NickHK

"Gary Keramidas" wrote in message
...
i've seen almost identical code in a few place, but it doesn't work,

the
variable always evaluates to nothing. why? i just need to test if the

other
workbook is open and if not, open it.

Dim WBook As Workbook
'...
On Error Resume Next
Set WBook = Workbooks("Workbook2")
On Error GoTo 0
If WBook Is Nothing Then
'your sorting code
End If


--


Gary









  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default testing for open workbook

Gary,
It does work if there is a WB called that name.
Comment out the "On Error.. and see what error is being raised.

NickHK

"Gary Keramidas" wrote in message
...
not for somebody else, only me. i have both workbooks open in one instance
of excel. both workbooks appear under the window menu. the variable always
evaluates to nothing.

don't know why it won't work.
--


Gary


"NickHK" wrote in message
...
Gary,
You're testing whether "Workbook2" is open in the current instance of
Excel.
If it is not, the WBook will be Nothing.

What I think you mean is "Is Workbook2 already opened by somebody else ?
For that you have to try and open it:
Set WBook = Workbooks.Open (..argument..)

You may want to check out .DisplayAlerts also.

NickHK

"Gary Keramidas" wrote in message
...
i've seen almost identical code in a few place, but it doesn't work,

the
variable always evaluates to nothing. why? i just need to test if the

other
workbook is open and if not, open it.

Dim WBook As Workbook
'...
On Error Resume Next
Set WBook = Workbooks("Workbook2")
On Error GoTo 0
If WBook Is Nothing Then
'your sorting code
End If


--


Gary









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
testing. do not open. S S Excel Worksheet Functions 1 April 16th 06 01:16 AM
Testing if file is open andreww Excel Programming 2 July 27th 05 06:07 PM
Testing for an open file Nigel Excel Programming 3 July 11th 05 06:41 AM
Testing if a file is open John Baker Excel Programming 3 January 29th 04 01:26 AM
Testing for open workbook nigelab Excel Programming 4 November 2nd 03 04:31 PM


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