作者:乔山办公网日期:
返回目录:word文档
使用 Replace() 函数。
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub Command1_Click()
Open "c:\新建文档zd内.doc" For Output As #1 '打开一容WORD文档
Print #1, "这是用VB新建的文档" '
Close
ShellExecute Me.hwnd, "open", "c:\新建文档.doc", vbNullString, vbNullString, 5
End
End Sub
打开前,先把 模板文件复制一份为临时文件名。然后打开这个文件,然后输出抄内容。最后再改名为 最终的文件名
参考:
Const TMPFILE = "~tmp.doc"
If Dir(App.Path & "\" & TMPFILE) <> "" Then
Kill TMPFILE
End If
FileCopy App.Path & "\" & 模板文件, App.Path & "\" & TMPFILE '目标位置可以是任意盘符任意目录,要求目录存在
'对zhidao TMPFILE 打开和处理
Name App.Path & "\" & TMPFILE As "输出报告1.doc"
Dim wordapp
Set wordapp = CreateObject("word.application")
With wordapp
.documents.open ("F:\1.doc")
.Visible = True
.activedocument.Content.Find.Execute FindText:=text1, ReplaceWith:=text2, Replace:=2
End With
祝你百成度功回!答