我有一个包含多个工作表的电子表格。我需要选择某些工作表中的所有行,以便可以将所有选定工作表中的所有行打印到单个文档中。
以下代码用于选择要打印的所有相关工作表和行。此代码有效,直到我尝试从第二个工作表中选择行。
Dim no_selected_worksheets As Boolean
no_selected_worksheets = True
Dim list_choose As Long
For list_choose = 0 To FormsToPrint.ListCount - 1
If FormsToPrint.Selected(list_choose) Then
With Worksheets(list_choose + 2)
If no_selected_worksheets Then
.Select 'This works.
.Rows.Select 'So does this.
no_selected_worksheets = False
Else
.Select (False) 'This works too..
.Rows.Select ' but here, VBA reports the error:
' "Select Method of Range class failed"
End If
End With
End If
Next
我该如何修复这个错误?