Dim oExcel As Variant
Dim oWB As Variant
'Set oWB = CreateObject("Object.Workbook")
Set oExcel = CreateObject("Excel.Application")
Set oWB = oExcel.Workbooks.Open("Z:\MPR\Maret 2017\31 - 03 -2017\DF\PAL - DF.xlsx")
oWB.Sheets(1).select
Dim oNumRow As Integer
'oNumRow = oWB.Sheets(1).UsedRange.Count
With oWB
oNumRow = oWB.Sheets(1).Cells(oWB.Sheets(1).Rows.Count, "A").End(xlUp).row 'error
End With
oNumRow = oWB.Sheets(1).Cells(oWB.Sheets(1).Rows.Count, 1).End.row 'error
oNumRow = oWB.Sheets(1).Range("A1", oWB.Sheets(1).Range("A1").End(xlDown).row).Rows.Count'error
如果我将Dim oExcel As Variant
更改为Dim oExcel As Excel.Application,那里的程序错误。谁能提出任何想法?我是为宏编程vba的新手
答案 0 :(得分:0)
如果您未在Excel VBA中运行代码,或以其他方式引用Microsoft Excel对象库,则该库中定义的常量都不可用于您的代码。你必须自己设定价值。
您可以将以下行添加到代码的开头:
Const xlUp As Long = -4162
Const xlDown As Long = -4121
它们是我在您发布的代码中看到的唯一两个常量,但是,如果您有其他常量,它们也应该添加到您的代码中。