å½ç¶å¯ä»¥ï¼ç¨DAOï¼å¯ä»¥å¨VBæ·»å DAOç»ä»¶ã
ç¶åï¼å®ä¹åæ°
'Database Connection
Dim cn As Workspace
Dim db As Database
Dim Rs As Recordset
Dim YOURPWD$, strSQL$, sContent$
'设置æ°æ®åº
Set cn = DBEngine.Workspaces(0)
Set db = cn.OpenDatabase(sDbPath, False, False, ";pwd=" & YOURPWD)
'æå¼æ°æ®åº
strSQL = "Select * From YourTable"
Set Rs = db.OpenRecordset(strSQL, , dbReadOnly)
'ååºä¸ä¸ªä¸ä¸ºNULLçå符串å段å¼
sContent = trim$(Rs!Item1)
--------------------------------------------------------------
'使ç¨åæå¨VBä¸å å
¥VBç»ä»¶
Dim xlsApp As Object, xlsBook As Object, xlsSheet As Object
Dim Row&, Col&
On Error GoTo ExcelInport_Err
'å建åºç¨Excelç¨åº
Set xlsApp = CreateObject("Excel.Application")
'Excel WorkBook çæ·»å
Set xlsBook = xlsApp.Workbooks.Add
âåå¾æ´»å¨çExcel Sheet
Set xlsSheet = xlsBook.ActiveSheet
'Excel Sheetçæ é¢
xlsSheet.Name = "Your Sheet Name"
'Excel Sheet å
容çå¡«å
With xlsSheet
Row = 1
'è¡
Col = 1
'å
.Cells(Row, Col).Value = "Your Fill Content"
End With
âExcel
xlsApp.Visible = True
Set xlsSheet = Nothing
Set xlsBook = Nothing
Set xlsApp = Nothing
Exit Sub
ExcelInport_Err:
'å
³éæ¶æ²¡ææ¶æ¯æ¡
xlsApp.DisplayAlerts = False
xlsApp.Quit
Set xlsApp = Nothing
温馨提示:内容为网友见解,仅供参考