使用工作簿作为变量

时间:2015-03-03 14:53:58

标签: excel-vba vba excel

我有两个变量Tempaw,它们都是工作簿。我想测试aw是否为空,如果是,则将其指定为activeworkbook。我试过了

if len(aw) = 0 then
 set aw = activeworkbook

但我一直收到错误。

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

1 个答案:

答案 0 :(得分:3)

Len函数用于确定字符串的长度。它不接受Workbook对象作为输入。 (不清楚工作簿的“长度”是什么意思!)

您要做的是测试aw是否为Nothing:

If aw Is Nothing Then Set aw = ActiveWorkbook