|
-
Jan 26th, 2009, 07:26 AM
#1
Thread Starter
Lively Member
[RESOLVED] Replace All text in MS Word Document - does not work properly
before i had problems with the publisher file, but well I just converted the publisher file to a word document... as I could actually do something with it...
but now i've ran into another problem...
when I do a find and replace, it will go through all the normal texts fine... but when it comes to text within a text box (drawn within word), it only does the first one and just ignores the rest..
i'm using the same code:
Code:
Dim word As New Microsoft.Office.Interop.Word.Application
Dim doc As Microsoft.Office.Interop.Word.Document
Try
doc = word.Documents.Open("d:\test.docx")
doc.Activate()
Dim myStoryRange As Microsoft.Office.Interop.Word.Range
For Each myStoryRange In doc.StoryRanges
With myStoryRange.Find
.Text = txtWORD_Find1.Text
.Replacement.Text = txtWORD_ReplaceWith1.Text
.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue
.Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
End With
Next myStoryRange
'For Each myStoryRange In doc.StoryRanges
' With myStoryRange.Find
' .Text = txtWORD_Find2.Text
' .Replacement.Text = txtWORD_ReplaceWith2.Text
' .Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue
' .Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
' End With
'Next myStoryRange
doc.SaveAs("d:\test1.docx")
word.Visible = True
Catch ex As Exception
MessageBox.Show("Error accessing Word document.")
End Try
which is from http://weblogs.asp.net/guystarbuck/a...ts-with-c.aspx
how can I make it go through ALL the textboxes and replace the text within them??
your assistance on the matter is greatly appreciated..
regards,
lianp..
Last edited by lianp; Jan 26th, 2009 at 08:21 AM.
Reason: Resolved
-
Jan 26th, 2009, 08:21 AM
#2
Thread Starter
Lively Member
Re: Replace All text in MS Word Document - does not work properly
yay...I found a solution.. not the fastest.. but it works..
resolved..sort of..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|