|
在excel的workbook_open中加入以下代码:
Sub 自动更新()
'
' 宏1 Macro
' duzili 记录的宏 2004-1-10
'
'
Sheet1.Select
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=MS Access 97 Database;DBQ=" & ThisWorkbook.Path & "\学生成绩.mdb;DefaultDir=" & ThisWorkbook.Path & ";DriverId=25;FIL=MS Access;MaxBufferSize=2048ageTimeout=5;" _
)), Destination:=Range("A1"))
.CommandText = Array( _
"SELECT 输入EXCEL.全部学号, 输入EXCEL.学号, 输入EXCEL.姓名, 输入EXCEL.政治, 输入EXCEL.语文, 输入EXCEL.数学, 输入EXCEL.英语, 输入EXCEL.体育, 输入EXCEL.素描, 输入EXCEL.色彩, 输入EXCEL.图案, 输入EXCEL.字" _
, "体, 输入EXCEL.电脑设计" & Chr(13) & "" & Chr(10) & "FROM 输入EXCEL 输入EXCEL" & Chr(13) & "" & Chr(10) & "ORDER BY 输入EXCEL.全部学号")
.Name = "查询来自 MS Access 97 Database"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheet2.Select
End Sub
|
|