我需要将 MS Access 表中的行导入 Excel。下面的 VBA 宏就是这样做的。
Sub Macro1()
'
'
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=MS Access Database;DBQ=C:\Documents and Settings\Administrator\My Documents\test_db.mdb;DefaultDir=C:\Documents and Setting" _
), Array( _
"s\Administrator\My Documents;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;" _
)), Destination:=Range("A1"))
.CommandText = Array( _
"SELECT Table1.ID, Table1.name, Table1.id, Table1.var1, Table1.var2" & Chr(13) & "" & Chr(10) & "FROM `C:\Documents and Settings\Administrator\My Documents\test_db`.Table1 Table1" _
)
.Name = "Query from MS Access Database"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertEntireRows
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub
MS Access 表 1
name id var1 var2
joe 1 23 34
当我运行一次宏时,我进入 Excel
name id var1 var2
joe 1 23 34
当我再次运行宏时,我进入 Excel
name id var1 var2 name id var1 var2
joe 1 23 34 joe 1 23 34
代替
name id var1 var2
joe 1 23 34
name id var1 var2
joe 1 23 34
你知道我应该改变什么才能将 MS Access 行作为现有数据下方的新数据行导入 Excel 吗?