Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
inserting a conditional "go to" command on a excel "if" function | Excel Worksheet Functions | |||
Complex if test program possible? If "value" "value", paste "value" in another cell? | Excel Discussion (Misc queries) | |||
Debug.Print "Test " vbCodeLineNumber & ": " & varName | Excel Programming | |||
Is there a "replace" or "Substitute" command in Excel's VB? | Excel Programming | |||
Looking for VB code to test for "RING" , "BUSY" disconnects or other signals | Excel Programming |