我收到消息
此外,我对编写文本
的方式表示怀疑Sub Read_Write_Document()
Dim p As Long, r As Long
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("C:\Documents and Settings\Desktop\Word_File_read_write_1.docx")
Dim i As Integer
i = 1
With wrdDoc_Read
For p = 1 To .Paragraphs.Count
Set tRange = .Range(Start:=.Paragraphs(p).Range.Start, End:=.Paragraphs(p).Range.End)
tString = tRange.Text
tString = Left(tString, Len(tString) - 1)
If InStr(1, tString, "1") > 0 Then
If Mid(tString, 1, 4) = "date" Then
tRange.Text = "DATE" ' Write Text
End If
End If
Next p
End With
.SaveAs ("C:\Documents and Settings\Desktop\Word_File_read_write_2.docx")
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub
答案 0 :(得分:0)
一些事情
<强> A 强>
始终建议使用Option Explicit
您已将单词文档声明为wrdDoc
,但正在使用wrdDoc_Read
更改行
With wrdDoc_Read
到
With wrdDoc
<强>乙强>
接下来,您的.SaveAs
例程超出With - End With
,因此会给您错误
<强> C 强>
您是在不关闭word文档的情况下直接退出单词应用程序。在wrdDoc.Close (False)
之后发布.SaveAs
总是好的,因为有些情况下已安装的加载项可以对文档进行更改,退出单词应用程序将再次提示.SaveAs
。< / p>
<强> d 强>
您可以使用.Find
和Replace