在线等!我这个代码怎么不能VB实现在word中替换文本,总是windows报错,程序关闭
Option Explicit Dim NewApp As Word.Application Dim NewDoc As Word.Document Dim NewRange As Word.Range Dim docname As String Dim retext As String Private Sub done_Click() Set NewApp = CreateObject("Word.Application") NewApp.Visible = True Set NewDoc = NewApp.Documents.Open(FileName:="D:\桌面\设计\程序设计\自动案件文档生成器\0003\12.doc") Set NewRange = NewDoc.Content docname = nametext.Text retext = replacetext.Text With NewRange.Find .ClearFormatting .Text = "1" .Replacement.ClearFormatting .Replacement.Text = retext .Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue End With With NewDoc .SaveAs FileName:="D:\桌面\设计\程序设计\自动案件文档生成器\0003\" & docname & ".DOC" .Close savechanges:=wdDoNotSaveChanges End With NewApp.Quit Set NewApp = NothingEnd Sub