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
基本上,我通过循环遍历源工作簿中的所有工作表,然后将目标工作簿中的destsheet
设置为与当前在原始工作簿中迭代的工作表同名的工作表。
如何测试该工作表是否存在?类似于:
If wkbkdestination.Worksheets(ThisWorkSheet.Name) Then