在访问 vba 中获取 excel 文件行的末尾
Get end of rows of an excel file within access vba
我正在使用 vba (dao) 以下列方式将 excel 文件导入访问:
Set db = CurrentDb
query = "SELECT DISTINCT * INTO MyTable" _
& " FROM [Excel 12.0 Xml;HDR=Yes;Database=" & filePath & "].[Sheet1$];"
db.Execute (query)
[Sheet1$]
是这里的关键字。我的 excel table header 从第 3 行开始。我想做类似 [Sheet1$A3:Lastline]
的事情。
有没有简单的方法获取lastline?或者我真的需要创建一个 VBA Excel Object,打开文件并计数吗?
或者,我可以更改 header 开始吗?例如,改用自定义导入方案?
提前致谢。
考虑使用记录集的计数查询,并在 make-table 查询中连接结果:
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim query As String
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT Count(*) AS RowCount" _
& " FROM [Excel 12.0 Xml;HDR=No;Database=" & filePath & "].[Sheet1$]")
query = "SELECT DISTINCT * INTO MyTable" _
& " FROM [Excel 12.0 Xml;HDR=Yes;" _
& " Database=" & filePath & "].[Sheet1$A3:A" & rst!RowCount & "];"
db.Execute (query)
rst.Close
Set rst= Nothing
Set db = Nothing
我正在使用 vba (dao) 以下列方式将 excel 文件导入访问:
Set db = CurrentDb
query = "SELECT DISTINCT * INTO MyTable" _
& " FROM [Excel 12.0 Xml;HDR=Yes;Database=" & filePath & "].[Sheet1$];"
db.Execute (query)
[Sheet1$]
是这里的关键字。我的 excel table header 从第 3 行开始。我想做类似 [Sheet1$A3:Lastline]
的事情。
有没有简单的方法获取lastline?或者我真的需要创建一个 VBA Excel Object,打开文件并计数吗?
或者,我可以更改 header 开始吗?例如,改用自定义导入方案?
提前致谢。
考虑使用记录集的计数查询,并在 make-table 查询中连接结果:
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim query As String
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT Count(*) AS RowCount" _
& " FROM [Excel 12.0 Xml;HDR=No;Database=" & filePath & "].[Sheet1$]")
query = "SELECT DISTINCT * INTO MyTable" _
& " FROM [Excel 12.0 Xml;HDR=Yes;" _
& " Database=" & filePath & "].[Sheet1$A3:A" & rst!RowCount & "];"
db.Execute (query)
rst.Close
Set rst= Nothing
Set db = Nothing