Object variable or With block variable not set error
error code
Dim sh As Range
Dim she as worksheet
MsgBox TypeName(Worksheets("项目")) 'Worksheet
she = Worksheets("项目") 'error!
sh = she.Range("a1")
If sh = "" Then
MsgBox "there is nothing in a1"
Else
MsgBox "there is sth in a1"
End If
right code
Dim sh As String
sh = Worksheets("项目").Range("a1")
If sh = "" Then
MsgBox "there is nothing in a1"
Else
MsgBox "there is sth in a1"
End If
说明- she类型为worksheet,报错语句意在将she赋值为工作表“项目”,工作表的赋值好像不能如此进行。