问题描述
将sim查找为字符串
昏暗的sReplace作为字符串
sFind ="{{"& "和}}"
sReplace ="Naresh sharma"
昏暗的Word作为Word.Application
Dim oDoc as Word.Document
''Dim oWord作为对象
''将oDoc视作对象
试试
oWord = CreateObject("Word.Application")
''soWord.Visible = True
oDoc = oWord.Documents.Add
oDoc = oWord.Documents.Open(TextBox1.Text)
oDoc.Activate()
将myStoryRange设置为Microsoft.Office.Interop.Word.Range
对于oDoc.StoryRanges中的每个myStoryRange
做
如果myStoryRange.StoryType = Word.WdStoryType.wdMainTextStory或myStoryRange.StoryType = Word.WdStoryType.wdTextFrameStory然后
使用myStoryRange.Find
.Text = sFind
.Replacement.Text = sReplace
.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue
.Execute(替换:= Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
结尾为
如果结束
myStoryRange = myStoryRange.NextStoryRange
循环播放,直到myStoryRange无效为止
下一个myStoryRange
oDoc.Save()
''System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc)
''元帅.ReleaseComObject(oDoc)
''''oDoc.Close()
''oDoc =没什么
''元帅.ReleaseComObject(oWord)
''oWord.Application.Quit()
''oWord =没什么
如果oDoc一无所有,那么
元帅.ReleaseComObject(oDoc)
oDoc =没什么
如果结束
如果oWord一无所有,那么
元帅.ReleaseComObject(oWord)
oWord =没什么
如果结束
捕获为ExternalException
MessageBox.Show(例如,ErrorCode,错误代码编号")
MessageBox.Show(例如StackTrace)
作为例外捕获Ex
结束Try
Dim sFind As String
Dim sReplace As String
sFind = "{{" & "" & "}}"
sReplace = "Naresh sharma"
Dim oWord As Word.Application
Dim oDoc As Word.Document
'' Dim oWord As Object
''Dim oDoc As Object
Try
oWord = CreateObject("Word.Application")
''soWord.Visible = True
oDoc = oWord.Documents.Add
oDoc = oWord.Documents.Open(TextBox1.Text)
oDoc.Activate()
Dim myStoryRange As Microsoft.Office.Interop.Word.Range
For Each myStoryRange In oDoc.StoryRanges
Do
If myStoryRange.StoryType = Word.WdStoryType.wdMainTextStory Or myStoryRange.StoryType = Word.WdStoryType.wdTextFrameStory Then
With myStoryRange.Find
.Text = sFind
.Replacement.Text = sReplace
.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue
.Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
End With
End If
myStoryRange = myStoryRange.NextStoryRange
Loop Until myStoryRange Is Nothing
Next myStoryRange
oDoc.Save()
''System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc)
''Marshal.ReleaseComObject(oDoc)
''''oDoc.Close()
''oDoc = Nothing
''Marshal.ReleaseComObject(oWord)
''oWord.Application.Quit()
''oWord = Nothing
If oDoc IsNot Nothing Then
Marshal.ReleaseComObject(oDoc)
oDoc = Nothing
End If
If oWord IsNot Nothing Then
Marshal.ReleaseComObject(oWord)
oWord = Nothing
End If
Catch ex As ExternalException
MessageBox.Show(ex.ErrorCode, "Error code no")
MessageBox.Show(ex.StackTrace)
Catch Ex As Exception
End Try
推荐答案
这篇关于如何找到"{{}}"来自.doc文件.我有.doc文件,其中某些字符串位于{{}}中,所以我想找到它&用其他字符串替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!