在线等!我这个代码怎么不能VB实现在word中替换文本,总是windows报错,程序关闭VB codeOption ExplicitDim N
在线等!我这个代码怎么不能VB实现在word中替换文本,总是windows报错,程序关闭
- VB code
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能够正常打开文本,但是就是替换文本的时候就要报错,不知道怎么回事,有没有人帮忙解决下啊,在线等,只要成功就结贴了
如果能QQ交流更好,有很多VB的疑问
[解决办法]
http://download.csdn.net/detail/veron_04/1627134
