【发布时间】:2020-07-06 16:05:07
【问题描述】:
我正在使用 Recordset 将 5 个查询从 Access 表单导出到 Excel,方法是循环 Excel 对象并在每次循环时创建一个新的 excel。最后,当我想突出显示第一张纸时,它会抛出一个错误:1004
<code>
'Once the loop ends
xlWorkbook.Sheets("xlsheet1").Select
xlSheet.Range("A3").Select
</Code>
But when I select the last sheet which is by default highlighted I don't get the error.
<code>
'Once the loop ends
xlWorkbook.Sheets("xlsheet5").Select
xlSheet.Range("A3").Select
</Code>
Can someone help me with this.
Thanks in Advance.
【问题讨论】:
-
您每次都在创建一个新工作簿。第五个工作簿没有第一个工作簿中的工作表。您可以运行
xlWorkbook(1 to 5)的数组。 -
另外,请使用
xlWorkbook.WorkSheets。