Excel应用程序定义的错误或对象定义的错误
我试图循环查看电子表格中的所有表单,并将单元格A4的内容清除到表单的末尾。
如果电子表格只包含1张表格,我就可以使用它。 如果它包含多个表单,则尝试清除表单2上的内容时会失败。
错误的行是.Range("A4", Range("A4").SpecialCells(xlLastCell)).ClearContents
当它碰到那条线时,我得到错误'Excel Application-defined or object-defined error'
你能看到我做错了吗?
Set book = Workbooks.Open("folder-containing-excel-spreadsheets") For Each Sheet In book.Sheets With Sheet .Range("A4", Range("A4").SpecialCells(xlLastCell)).ClearContents End With Next book.Save book.Close
尝试改变
.Range("A4", Range("A4").SpecialCells(xlLastCell)).ClearContents
至
.Range("A4", .Range("A4").SpecialCells(xlLastCell)).ClearContents
你错过了.
Range("A4").SpecialCells(xlLastCell)
等等, Range("A4").SpecialCells(xlLastCell)
总是试图在第一张纸上find最后一个单元格