Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default How to test success of a "Set" command?

2003/2007

There is a probable a better way. The GoToWb opens at the '******* line of code. If the file
has not opened by '$$$$$$$$$ line then I have the code line - If Err.Number 0 Then

Workbooks(GoToWb).Activate If Err.Number 0 Then
On Error GoTo 0
On Error Resume Next
Set Windows(GoToWb) = Workbooks(GoToWb)
On Error GoTo 0
On Error Resume Next
Set Workbooks(GoToWb) = Workbooks.Open(Filename:=GoToPath & GoToWb) '*******
On Error GoTo 0
On Error Resume Next
Set Workbooks(GoToWb) = Workbooks.Open(Filename:=Application.DefaultFilePa th & _
"\" & GoToWb) '$$$$$$$$$
If Err.Number 0 Then
.......
Endif
Endif

Since the file opens at '******* then the Set command at '$$$$$$$$$ produces an error when
the file is already open.

How do I test the success of the previous Set command so that I do not produce an error?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default How to test success of a "Set" command?

Your code has me at a bit of a loss so here is a generallized method...

dim wbkOpen as workbook

on error resume next
set wbkOpen = workbooks("MyBook.xls")
on error goto 0

is wbkOpen is nothing then _
set wbkOpen = Workbooks.Open("C:\Mybook.xls")

'Note that Nothing is the test for an object being initialized
--
HTH...

Jim Thomlinson


" wrote:

2003/2007

There is a probable a better way. The GoToWb opens at the '******* line of code. If the file
has not opened by '$$$$$$$$$ line then I have the code line - If Err.Number 0 Then

Workbooks(GoToWb).Activate If Err.Number 0 Then
On Error GoTo 0
On Error Resume Next
Set Windows(GoToWb) = Workbooks(GoToWb)
On Error GoTo 0
On Error Resume Next
Set Workbooks(GoToWb) = Workbooks.Open(Filename:=GoToPath & GoToWb) '*******
On Error GoTo 0
On Error Resume Next
Set Workbooks(GoToWb) = Workbooks.Open(Filename:=Application.DefaultFilePa th & _
"\" & GoToWb) '$$$$$$$$$
If Err.Number 0 Then
.......
Endif
Endif

Since the file opens at '******* then the Set command at '$$$$$$$$$ produces an error when
the file is already open.

How do I test the success of the previous Set command so that I do not produce an error?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default How to test success of a "Set" command?

Thanks Jim


Jim Thomlinson wrote:

Your code has me at a bit of a loss so here is a generallized method...

dim wbkOpen as workbook

on error resume next
set wbkOpen = workbooks("MyBook.xls")
on error goto 0

is wbkOpen is nothing then _
set wbkOpen = Workbooks.Open("C:\Mybook.xls")

'Note that Nothing is the test for an object being initialized

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
inserting a conditional "go to" command on a excel "if" function velasques Excel Worksheet Functions 5 March 10th 06 08:16 PM
Complex if test program possible? If "value" "value", paste "value" in another cell? jseabold Excel Discussion (Misc queries) 1 January 30th 06 10:01 PM
Debug.Print "Test " vbCodeLineNumber & ": " & varName TommySzalapski[_32_] Excel Programming 1 August 2nd 05 05:17 PM
Is there a "replace" or "Substitute" command in Excel's VB? [email protected] Excel Programming 2 December 5th 03 07:56 AM
Looking for VB code to test for "RING" , "BUSY" disconnects or other signals BruceJ[_2_] Excel Programming 3 November 20th 03 01:55 AM


All times are GMT +1. The time now is 01:02 PM.

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

About Us

"It's about Microsoft Excel"