|
7#
發(fā)表于 2003-11-13 16:51:00
|
只看該作者
使用模板也還是需要編程的
我這兒暫時還沒有范例數(shù)據(jù)庫,等有啦再上傳吧
問題一: 實際上word的變量就是你敲入一個特殊的字符串
例如
代號 DH 級別 JB 起止
時間 MM月DD日HS時MS分
至MM月DD日HD時MD分
值勤
人員 ZQRY 記錄員 JLY
負責人 FZR
上述需要 填寫的內容就使用 這些 字符串,然后還是用access的vba進行編程,就是找到這些你設定的字符串,然后找到他們,把他們一一替換為對應你提取的數(shù)據(jù)
范例代碼 其中一段,看看思路)
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 = "保衛(wèi)"
End If
If gCurGuardTask.TaskType = TaskType.JinWei Then
strTask = "警衛(wèi)"
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
|
|