我在互联网上搜索了整整一天的时间,无法找到解决我问题的方法。我有来自报表的数据,我正在Access 2016中进行一些数据处理并将其踢回Excel。
我正在尝试使用Access模块来分离数据,以便在A列的更改数据行之间提供间隔。对于整个编程领域,我还是一个新手,所以对于代码有点古怪我深表歉意。 。
下面的代码给出了一个错误“运行时错误'424':所需对象”我只是不确定从这里要去哪里。错误发生在以下行:
r = xlApp.Sheets(Pen_105_List_PenetrationWithFin).Cells(Rows.Count, “ A”)。End(xlUp).Row
感谢您的指导。
Function FixExcel()
Dim xlApp As Object
Dim xlBook As Object
Dim r As Long
Dim mcol As String
Dim i As Long
Dim ws As Long
Set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False
xlApp.DisplayAlerts = False
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open("\\iocc-
web01\dcs\WorkForceDB\NICC\DailyListPen" & Format(Date, "mm-dd-yyyy") &
".xlsx")
' find last used cell in Column A
r = xlApp.Sheets(Pen_105_List_PenetrationWithFin).Cells(Rows.Count,
"A").End(xlUp).Row
' get value of last used cell in column A
mcol = xlApp.Sheets(Pen_105_List_PenetrationWithFin).Cells(r, 1).Value
' insert rows by looping from bottom
For i = r To 2 Step -1
If xlApp.Sheets(Pen_105_List_PenetrationWithFin).Cells(i, 1).Value <>
mcol Then
mcol = xlApp.Sheets(Pen_105_List_PenetrationWithFin).Cells(i,
1).Value
xlApp.Sheets(Pen_105_List_PenetrationWithFin).Rows(i + 1).Insert
xlApp.Sheets(Pen_105_List_PenetrationWithFin).Rows(i + 1).Insert
End If
Next i
xlBook.SaveAs "\\iocc-web01\dcs\WorkForceDB\NICC\DailyListPen" &
Format(Date, "mm-dd-yyyy") & ".xlsx"
xlBook.Close
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
End Function