有几个可能会用到的控件需要引用一下: Microsoft Office 9.0 Object Library Microsoft Word 9.0 Object Library'…… Set obj = New Word.Application obj.Documents.Open Filename '打开指定的Word文档 obj.Visible = False Dim doccount As Integer doccount = obj.Documents(1).BuiltInDocumentProperties(wdPropertyPages) '得到word文档的页数 obj.Documents(1).PrintOut DoEvents ……
这里有个函数是替换字符串的 但这个总是执行后没有替换成功 帮忙看看我的代码 号码 谢谢了 Private Sub Command1_Click() Dim a As Object Set a = New Word.Applicationa.Documents.Open "D:\刘克敏文件\文章\杂文\1.doc" ReplaceInWordDoc "aaa", "wasai" a.Documents.Save a.Quit Set a = Nothing End Sub Public Sub ReplaceInWordDoc(findString As String, ReplString As String) Dim r As Word.Range Dim f As Word.Find
Set r = ActiveDocument.Range Set f = r.Find
With f .ClearFormatting .Execute Replace:=wdReplaceAll, ReplaceWith:=ReplString, FindText:=findString End With End Sub
Microsoft Office 9.0 Object Library
Microsoft Word 9.0 Object Library'……
Set obj = New Word.Application
obj.Documents.Open Filename '打开指定的Word文档
obj.Visible = False
Dim doccount As Integer
doccount = obj.Documents(1).BuiltInDocumentProperties(wdPropertyPages) '得到word文档的页数
obj.Documents(1).PrintOut
DoEvents
……
数据可以用PASTE填入,打印可用DOCUMENT.PRINT方法.
'这里有源代码
打开和打印文档已经实现了
请问如何修改word中的内容
比如把文中的"aaaa"替换为"bbbb"
这里有个函数是替换字符串的 但这个总是执行后没有替换成功 帮忙看看我的代码
号码 谢谢了
Private Sub Command1_Click()
Dim a As Object
Set a = New Word.Applicationa.Documents.Open "D:\刘克敏文件\文章\杂文\1.doc"
ReplaceInWordDoc "aaa", "wasai"
a.Documents.Save
a.Quit
Set a = Nothing
End Sub
Public Sub ReplaceInWordDoc(findString As String, ReplString As String)
Dim r As Word.Range
Dim f As Word.Find
Set r = ActiveDocument.Range
Set f = r.Find
With f
.ClearFormatting
.Execute Replace:=wdReplaceAll, ReplaceWith:=ReplString, FindText:=findString
End With
End Sub