可以实现,两个知识点:
1、ADO连接
2、SQL语言
另外就是不要忘了要在Excel中引用Access
下面是我做的一个在Word 中调Access的代码,可参考。
Sub Open_Acs()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql, i, a, b, c, d, e, f
sql = "select id,题目 , 内容 from 卡片表 "
conn.Provider = "microsoft.jet.oledb.4.0"
conn.Open "d:\aa\su.mdb"
rs.Open sql, conn, adOpenKeyset, adLockOptimistic, adCmdText
a = "d:\aa\"
e = 1
Do While (Not rs.EOF)
Application.Documents.Add
c = rs("内容")
ActiveDocument.Range(0, 0) = (c & "=================================" & Chr(13))
c = ""
b = Mid(c, 3, 6)
'只是不要忘了引用ACCSEE
ActiveDocument.Range(0, 0) = (b & Chr(13))
f = a & b & e & ".doc"
b = ""
ActiveDocument.SaveAs FileName:=f, FileFormat:=wdFormatDocument
ActiveDocument.Close
e = e + 1
rs.MoveNext
Loop
conn.Close
Set conn = Nothing
e = e & "篇"
MsgBox e
End Sub
我这段代码的作用是将Access中一个表的与内容读出来,并生成一个Word文档。然后保存,
[此贴子已经被作者于2004-6-8 22:01:52编辑过] |