|
-
Dec 1st, 2003, 01:23 AM
#1
Thread Starter
Member
Autoshapes in MS Word
Hi All,
I have been trying to write a Word VBA Macro Code which can Search and Replace the text in AutoShapes in a word document.
I have been able to do the same with Excel, however have been unsuccessful in doing so for the Word documents.
Please can someone help me in doing this.
Thanks in advance,
Lonely
***********The Excel Code is *************
Sub Test1()
Dim Sh As Shape
Dim ShRng As ShapeRange
Dim SubSh As Shape
On Error Resume Next
For Each Sh In Worksheets("Sheet1").Shapes
Set ShRng = Sh.Ungroup
If Err = 0 Then
For Each SubSh In ShRng
SubSh.TextFrame.Characters.Text = Replace(SubSh.TextFrame.Characters.Text, "XXX", "YYY")
Next SubSh
ShRng.Regroup
Else
Err.Clear
Sh.TextFrame.Characters.Text = Replace(Sh.TextFrame.Characters.Text, "XXX", "YYY")
End If
Next Sh
End Sub
*************End Code**************
I Was Born Lonely, Lived Lonely .... And Will Die Lonely!!
-
Dec 3rd, 2003, 09:15 PM
#2
Fanatic Member
In Word the property is called TextRange instead of Characters.
VB Code:
Sub Test1()
Dim Sh As Shape
Dim ShRng As ShapeRange
Dim SubSh As Shape
On Error Resume Next
For Each Sh In ActiveDocument.Shapes
Set ShRng = Sh.Ungroup
If Err = 0 Then
For Each SubSh In ShRng
SubSh.TextFrame.TextRange.Text = Replace(SubSh.TextFrame.TextRange.Text, "XXX", "YYY")
Next SubSh
ShRng.Regroup
Else
Err.Clear
Sh.TextFrame.TextRange.Text = Replace(Sh.TextFrame.TextRange.Text, "XXX", "YYY")
End If
Next Sh
End Sub
-
Dec 4th, 2003, 01:21 AM
#3
Thread Starter
Member
Hi Workhorse,
This works wonderfully, expect for just one hitch, how do i define the options like "Match Whole Word", Match case" etc.
Thanks again,
Lonely
I Was Born Lonely, Lived Lonely .... And Will Die Lonely!!
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
|