Find text in textbox in word document
I want c# code to replace text inside textbox in word document.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Bala muruganPosted Jul 21, 2010, 7:44 PM
I have got similar issue in C# while editing the word doc. Can you please share your fix for me?
Thanks,
Bala.
Ahmed Ayman YassinPosted May 17, 2010, 1:57 PM
Dim word As New Word.Application
Dim doc As Word.Document
word.Documents.Open("c:\abc.doc")
word.Visible = True
doc = word.ActiveDocument
FindandReplace(doc, "vbcode", "csharp code")
Sub FindandReplace(ByVal doc As Word.Document, ByVal Findtext As String, ByVal Replacetext As String)
Dim myStoryRange = doc.Range()
'First search the main document using the Selection
With myStoryRange.Find
.Text = Findtext
.Replacement.Text = Replacetext
.Forward = True
.Wrap = Word.WdFindWrap.wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute(Replace:=Word.WdReplace.wdReplaceAll)
End With
'Now search all other stories using Ranges
For Each myStoryRange In doc.StoryRanges
If myStoryRange.StoryType <> Word.WdStoryType.wdMainTextStory Then
With myStoryRange.Find
.Text = Findtext
.Replacement.Text = Replacetext
.Wrap = Word.WdFindWrap.wdFindContinue
.Execute(Replace:=Word.WdReplace.wdReplaceAll)
End With
Do While Not (myStoryRange.NextStoryRange Is Nothing)
myStoryRange = myStoryRange.NextStoryRange
With myStoryRange.Find
.Text = Findtext
.Replacement.Text = Replacetext
.Wrap = Word.WdFindWrap.wdFindContinue
.Execute(Replace:=Word.WdReplace.wdReplaceAll)
End With
Loop
End If
Next myStoryRange
End Sub
Ahmed Ayman YassinPosted May 16, 2010, 11:54 AM
CrishPosted May 16, 2010, 8:51 AM
use below link for your solution
http://blogs.techrepublic.com.com/howdoi/?p=190
Don't forget to Mark Do you like this Answer that solved your problem!