Dim wkbkdestination As Workbook
Dim destsheet As Worksheet
For Each ThisWorkSheet In wkbkorigin.Worksheets
'this throws subscript out of range if there is not a sheet in the destination
'workbook that has the same name as the current sheet in the origin workbook.
Set destsheet = wkbkdestination.Worksheets(ThisWorkSheet.Name)
Next
Run Code Online (Sandbox Code Playgroud)
基本上,我遍历原始工作簿中的所有工作表,然后destsheet在目标工作簿中将其设置为与原始工作簿中当前迭代的工作表相同的工作表.
如何测试该表是否存在?就像是:
If wkbkdestination.Worksheets(ThisWorkSheet.Name) Then
Run Code Online (Sandbox Code Playgroud) 我想知道如果存在工作簿中的工作表,是否存在返回True或False的清除功能?
如果可以在不跳过错误处理的情况下完成它,那将是好的,但不是必需的.
我发现的唯一的东西并不真正起作用:
On Error Resume Next
If (Worksheets("wsName").Name <> "") Then
Debug.Print "Worksheet exists!"
Else
Debug.Print "Worksheet doesn't exist!"
End If
On Error GoTo ErrHandler
Run Code Online (Sandbox Code Playgroud)