Hi guys,
Im new to word VBA, so I hope you can help me out with this problem. I have a group of 1 circle, 4 lines, and 3 textboxes in word, and they have names. I want to change the text of textbox "NBL-02". I used selection.find and .replacement but it didnt work, or it added new text in the second line, not replace or change the text of textbox. I searched online and tried to use storyranges but it didnt let me search for the name of textbox. My english is not good, so hope it makes sense to you guys.
Code:
Sub trail2()
Dim sh As Shape, a As Long, invi_shp As Shape, b As Long, new_text As Variant
Dim new_string As Variant, new_vol As Variant, rng As Range, old_text As Variant
Dim mystoryrange As Range
For Each sh In ActiveDocument.Shapes
If sh.Type = msoGroup Then
'Set invi_sh = sh
For a = 1 To sh.GroupItems.Count
If sh.GroupItems(a).Name = "Vol_NBT_Int_1" Then
Set invi_sh = sh.GroupItems(a)
old_text = invi_sh.TextFrame.TextRange.Text
invi_sh.Select
With Selection.Find
.Text = old_text
.Replacement.Text = "400"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
With Selection
.Collapse
End With
End If
Next a
End If
Next
For Each mystoryrange In ActiveDocument.StoryRanges
If mystoryrange.StoryType = wdTextFrameStory Then
mystoryrange.Select
With mystoryrange.Find
.Text = "1200"
.Replacement.Text = "20"
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
End If
Next mystoryrange
End Sub