Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Put the following code in a workbook:
Sub VariableTest() Dim anyR As Range Set anyR = Selection anyR.Parent.Parent.Close False If anyR Is Nothing Then MsgBox "is nothing" Else MsgBox "is Not nothing" End If End Sub Now go to another workbook and run it. Since the workbook which anyR pointed to is now closed, I expected anyR to be nothing. But it is not. What I want to do is to test if the workbook has been closed by seeing if anyR is nothing. The only way I see is something like this: dim wS as worksheet On Error Resume next set wS = nothing 'in case it has previously been set set wS = anyR.Parent On Error goto 0 I can then test if wS is nothing. I would much prefer a test directly on the range variable without using an error trap, as it is easy to forget to remove an error trap. And the above is several lines of code (I can always put in a function) Is there a way to do a direct test? Bob |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Variable Case issue | Excel Programming | |||
setting a range variable equal to the value of a string variable | Excel Programming | |||
Case statement in variable range | Excel Programming | |||
Problem with copying variable(s) to cell(s) and converting strings to mixed case | Excel Programming |