在Excel中将当前WorkBook分配给Workbook对象

时间:2012-10-12 11:27:17

标签: excel excel-vba excel-2010 vba

我尝试将当前工作簿分配给工作簿对象:

Dim wb As Workbook, ws As Worksheet, rng As Range

wb = ThisWorkbook

在此实例中,代码正在运行,并且是当前活动的工作簿。但我得到以下错误,我错了:

91 - Object variable or With block variable not set

1 个答案:

答案 0 :(得分:3)

将对象分配给变量时,必须使用Set

Set wb =ThisWorkbook