2015-02-12 161 views

回答

2

是的,如果Sheets("Output")不是真的存在,那么会出错。
您正试图访问不存在的对象。

试试这个:我们使用OERNOEG0变量赋值过程中抑制错误

Dim wsop As Worksheet 

On Error Resume Next 
Set wsop = Sheets("Output") 
On Error Goto 0 

If wsop Is Nothing Then 
    Set wsop = Sheets.Add(, Sheets(Sheets.Count)) 'after last sheet 
    wsop.Name = "Output" 
End If 

多加留意。
要了解更多关于error handling请查看链接。 HTH。

0

试试这个

Sub test() 

Dim wsSheet As Worksheet 
On Error Resume Next 
Set wsSheet = Sheets("Output") 'declare before check 
On Error GoTo 0 
If wsSheet Is Nothing Then 
Worksheets.Add.Name = "Output" 
End If 

End Sub 
相关问题