北京 | 上海 | 天津 | 重庆 | 广州 | 深圳 | 珠海 | 汕头 | 佛山 | 中山 | 东莞 | 南京 | 苏州 | 无锡 | 常州 | 南通 | 扬州 | 徐州 | 杭州 | 温州 | 宁波 | 台州 | 福州 | 厦门 | 泉州 | 龙岩 | 合肥 | 芜湖 | 成都 | 遂宁 | 长沙 | 株洲 | 湘潭 | 武汉 | 南昌 | 济南 | 青岛 | 烟台 | 潍坊 | 淄博 | 济宁 | 太原 | 郑州 | 石家庄 | 保定 | 唐山 | 西安 | 大连 | 沈阳 | 长春 | 昆明 | 兰州 | 哈尔滨 | 佳木斯 | 南宁 | 桂林 | 海口 | 贵阳 | 西宁 | 乌鲁木齐 | 包头 |
代码如下:
Dim strTemplate As String
Dim strFileName As String
Dim objApp As Object 'New Word.Application
Dim objDoc As Object 'Word.Document
Dim objField As Object 'Word.Field
Dim rst As Object
Dim blnNoQuit As Boolean
strTemplate = CurrentProject.Path & "\模板\入院录模板.doc"
Set objApp = CreateObject("Word.Application") '创建word对象
Set objDoc = objApp.Documents.Open(strTemplate) '打开word模块文档
Set rst = CurrentDb.OpenRecordset("SELECT * FROM 表1 WHERE 病员号='" & 病员号 & "'", , 4)
If Not rst.EOF Then
strFileName = CurrentProject.Path & "\存放位置\" & rst!姓名 & "入院录" & ".doc"
If Dir(strFileName) <> "" Then Kill strFileName '如果文件已存在,先删除已有文件
objDoc.FormFields("姓名").result = rst!姓名
objDoc.FormFields("性别").result = rst!性别
objDoc.FormFields("年龄").result = rst!年龄
objDoc.FormFields("病区").result = rst!病区
objDoc.FormFields("床号").result = rst!床号
objDoc.FormFields("婚否").result = rst!婚否
.......
End If
rst.Close
objDoc.SaveAs strFileName
Dim MyText As String
MyText = Me.姓名
Set objDoc = objApp.Documents.Open(strFileName)
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.Range.Text = MyText
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
不知道这段代码错在哪里,不能为导出的wOrd文档添加页眉,望老师们予以指导,在此感谢了.