Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba Excel应用程序定义或对象定义错误_Vba_Excel - Fatal编程技术网

Vba Excel应用程序定义或对象定义错误

Vba Excel应用程序定义或对象定义错误,vba,excel,Vba,Excel,我试图在电子表格中的所有表格中循环,并清除表格末尾A4单元格的内容 我有它的工作,如果电子表格只包含1页。 如果包含多张工作表,则尝试清除工作表2上的内容时失败 错误行是.Range(“A4”,Range(“A4”).SpecialCells(xlLastCell)).ClearContents 当它到达该行时,我得到错误“Excel应用程序定义或对象定义错误” 你能看出我做错了什么吗 Set book = Workbooks.Open("folder-containing-excel-

我试图在电子表格中的所有表格中循环,并清除表格末尾A4单元格的内容

我有它的工作,如果电子表格只包含1页。 如果包含多张工作表,则尝试清除工作表2上的内容时失败

错误行是
.Range(“A4”,Range(“A4”).SpecialCells(xlLastCell)).ClearContents

当它到达该行时,我得到错误“Excel应用程序定义或对象定义错误”

你能看出我做错了什么吗

    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


范围(“A4”)之前,您错过了
。特殊单元格(xlLastCell)
因此,
范围(“A4”)。特殊单元格(xlLastCell)
总是尝试在第一张纸中找到最后一个单元格。我是说漏点。真不敢相信我爱上了旧的漏点程序:)谢谢你的发现!
.Range("A4", .Range("A4").SpecialCells(xlLastCell)).ClearContents