Reputation: 25
I have two variables Temp
and aw
that are both workbooks. I want to test if aw
is empty, and if so, assign it to be the activeworkbook. I tried
if len(aw) = 0 then
set aw = activeworkbook
but I kept getting an error.
Static aw As Workbook
Dim Temp As Workbook
Set Temp = ActiveWorkbook
If Temp = aw Then
GoTo Here
ElseIf Len(aw) = 0 Then
Set aw = ActiveWorkbook
Else
Application.ScreenUpdating = False
aw.Activate
ActiveSheet.Range("K5:K7").Clear
Set aw = Temp
aw.Activate
Application.ScreenUpdating = True
End If
Here:
aw.Activate
ActiveSheet.Range("K5").Select
Selection.Value = 15 * 60
Upvotes: 1
Views: 85
Reputation: 38540
The Len
function is used to determine the length of a string of characters. It doesn't accept Workbook objects as input. (Not clear what the "length" of a workbook would be anyway!)
What you want to do instead is test whether aw
is Nothing:
If aw Is Nothing Then Set aw = ActiveWorkbook
Upvotes: 3