我一直试图解决这个问题一个多星期了。我需要Excel,通过Access将撇号添加到Excel文件的第二列。我首先在Excel中测试了与Access分开的vba并且它工作正常。但是,当我尝试使用适当的(或者我认为的)对象引用来执行via Access时,在单击命令按钮后,我通过Access获得“溢出”消息。
错误是运行时错误6“溢出”
它指向这一行:
For i = 1 To .Cells(Rows.Count, mc).End(xlUp).Row
Private Sub cmdImport_Click()
Dim objExcel As Excel.Application
Dim objWB As Excel.Workbook
Dim objWS As Excel.Worksheet
Dim i As Integer
Set objExcel = New Excel.Application
objExcel.Visible = True
Set objWB = Workbooks.Open("R:\GMI\Drop\AP04 2018.xlsx", , False)
Set objWS = objWB.ActiveSheet
With objWS
.Range("a2:a7").EntireRow.Insert
mc = 2 'column I
For i = 1 To .Cells(Rows.Count, mc).End(xlUp).Row
.Cells(i, mc).Value = "'" & .Cells(i, mc)
Next i
End With
objWB.SaveAs "C:\EMI\Drop\JV.xlsx"
objWB.Close
Set objWB = Nothing
objExcel.Quit
Set objExcel = Nothing
DoCmd.TransferSpreadsheet acImport, , "Transactions", "R:GEMI\Drop\TransToday.xlsx", True
MsgBox "Pre-import/Import complete", vbOKOnly
End Sub