从其他工作簿中删除单元格

时间:2018-08-07 12:42:19

标签: excel

对不起,现在,如何从其他工作簿中删除数据? 我要删除文件Victoria.xlsx中的数据。这不起作用...能帮我吗?谢谢!

Sub BorrarContenidoVictoria()

    Dim wbThat As Workbook
    Dim wsThat As Worksheet
    Dim wbThatPath As String
    Dim lRow As Long

    '~~> Change path accordingly
    wbThatPath = "/Users/jose/Desktop/Victoria.xlsx"

    Set wbThat = Workbooks.Open(wbThatPath)
    Set wsThat = wbThat.Sheets("Hoja1")

        lRow = wsThat.Range("A" & Rows.Count).End(xlUp).Row

        wsThat.Range("A2" & lRow).ClearContents


End Sub

1 个答案:

答案 0 :(得分:0)

这会删除Hoja1的{​​{1}}中的所有单元格:

Victoria.xlsx

Sub BorrarContenidoVictoria() Dim wbThat As Workbook Dim wsThat As Worksheet wbThatPath = "/Users/jose/Desktop/Victoria.xlsx" Set wbThat = Workbooks.Open(wbThatPath) Set wsThat = wbThat.Sheets("Hoja1") wsThat.Cells.Delete wbThat.Close True End Sub 关闭工作簿并保存更改- Close Method MSDN