|
使用模板也还是需要编程的
我这儿暂时还没有范例数据库,等有啦再上传吧
问题一: 实际上word的变量就是你敲入一个特殊的字符串
例如
代号 DH 级别 JB 起止
时间 MM月DD日HS时MS分
至MM月DD日HD时MD分
值勤
人员 ZQRY 记录员 JLY
负责人 FZR
上述需要 填写的内容就使用 这些 字符串,然后还是用access的vba进行编程,就是找到这些你设定的字符串,然后找到他们,把他们一一替换为对应你提取的数据
范例代码其中一段,看看思路)
Dim vsWordApp As Word.Application
On Error Resume Next
Err.Clear
Set vsWordApp = GetObject(, "Word.Application")
If Err.Number Then
Set vsWordApp = CreateObject("Word.Application")
Err.Clear
End If
'If vsWordApp.Visible Then vsWordApp.Visible = False
On Error GoTo ErrHandler
Dim vsWordDoc As Word.Document
vsWordApp.Documents.Add Template:=App.Path & "\" & Trim(strDocTemplateName)
Set vsWordDoc = vsWordApp.ActiveDocument
Dim vsrange As Word.Range
Set vsrange = vsWordApp.ActiveDocument.Content
With vsrange.Find
.Execute FindText:="LSXH", replacewith:=Trim(Me.cboRecordSequence.Text), Replace:=wdReplaceAll
.Execute FindText:="MM", MatchCase:=True, replacewith:=Month(Me.DTPStartTime.Value), Replace:=wdReplaceAll
.Execute FindText:="DD", replacewith:=Day(Me.DTPStartTime.Value), Replace:=wdReplaceAll
.Execute FindText:="HS", replacewith:=Hour(Me.DTPStartTime.Value), Replace:=wdReplaceAll
.Execute FindText:="MS", MatchCase:=True, replacewith:=Minute(Me.DTPStartTime.Value), Replace:=wdReplaceAll
.Execute FindText:="HD", replacewith:=Hour(Me.DTPEndTime.Value), Replace:=wdReplaceAll
.Execute FindText:="MD", MatchCase:=True, replacewith:=Minute(Me.DTPEndTime.Value), Replace:=wdReplaceAll
.Execute FindText:="DH", replacewith:=Trim(Me.cboTaskCode.Text), Replace:=wdReplaceAll
.Execute FindText:="JB", replacewith:=Trim(Me.txtTaskLevel.Text), Replace:=wdReplaceAll
.Execute FindText:="ZQRY", replacewith:=Trim(Me.cboRecordWatch.Text), Replace:=wdReplaceAll
.Execute FindText:="JLY", replacewith:=Trim(Me.txtRecorder.Text), Replace:=wdReplaceAll
.Execute FindText:="FZR", replacewith:=Trim(Me.txtResponser.Text), Replace:=wdReplaceAll
.Execute FindText:="BT", replacewith:=Trim(Me.txtRecordTitle.Text), Replace:=wdReplaceAll
Dim strTask As String
If gCurGuardTask.TaskType = TaskType.BaoWei Then
strTask = "保卫"
End If
If gCurGuardTask.TaskType = TaskType.JinWei Then
strTask = "警卫"
End If
.Execute FindText:="JW", replacewith:=Trim(strTask), Replace:=wdReplaceAll
Dim strXH() As String
strXH = Split(Trim(Me.cboRecordSequence.Text), "―")
.Execute FindText:="XH", replacewith:=strXH(UBound(strXH)), Replace:=wdReplaceAll
'.Execute FindText:="CONTENT", replacewith:=gcurGuardRecorder.Content, Replace:=wdReplaceAll
End With
With vsWordApp.Selection.Find
.Text = "CONTENT"
.Wrap = wdFindContinue
.Execute
If UCase(vsWordApp.Selection) = "CONTENT" Then
vsWordApp.Selection.Text = gcurGuardRecorder.Content
End If
vsWordApp.Selection.HomeKey Unit:=wdStory
End With
With vsWordApp.Selection.Find
.Text = "YM"
.Wrap = wdFindContinue
.Execute
If UCase(vsWordApp.Selection) = "YM" Then
' vsWordApp.Selection.Text = CStr(vsWordApp.Selection.HeaderFooter.PageNumbers.Count + 1)
End If
End With
|
|