使用Access VBA删除多个工作表中的行和列

时间:2016-12-03 13:59:04

标签: excel vba access-vba ms-access-2010

目录中的数百个xlsx文件将导入MS Access 2010数据库。

我在导入之前要清理工作表。

问题是:如何删除A列中没有数据的所有行以及从O到XFD的所有列?

以下代码适用于一个文件一次 enter image description here

必须删除所有红色。

Private Sub Comand_Click()
    Dim FullPath As String
    Dim oXL As Object, oWb As Object, oWs As Object
    FullPath = "D:\Access\_Test_XlsImport\FileName.xlsx"
    Set oXL = CreateObject("Excel.Application")
    Set oWb = oXL.Workbooks.Open(FullPath)
    Set oWs = oWb.Sheets("Worksheet_name")
    oXL.Visible = True

    With oWs
        .Columns("O:XFD").Delete
        .Rows("xx:xx").Delete ' <---problem to identify the starting point to delete below..
    End With
    oWb.Save

CleanUp:
    oWb.Close False
    oXL.Quit
    Set oWb = Nothing
    Set oXL = Nothing
    Set oWs = Nothing
End Sub

0 个答案:

没有答案