![]() |
|
|
|
#1
|
|||
|
|||
|
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
Last edited by macropod; 12-22-2013 at 03:10 PM. Reason: Replaced 'quoted' code with code tags & formatting |
|
#2
|
||||
|
||||
|
I don't see any reference to textbox a named "NBL-02" in your code which, it seems to me, could be reduced to:
Code:
With ActiveDocument.Shapes("NBL-02").TextFrame.TextRange.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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Macro to find text and replace with form field containing that text
|
iiiiifffff | Word VBA | 16 | 06-04-2016 01:47 AM |
Locked document with checkboxes AND textboxes
|
Georg1e | Word | 1 | 03-01-2013 01:26 PM |
| <object> reference appearing next to textboxes | bblouin | Word | 0 | 10-19-2012 08:50 AM |
Select all textboxes in Word document
|
msword270 | Word | 1 | 01-12-2012 11:41 AM |
Many textboxes on top of each others?
|
Giygas | PowerPoint | 1 | 12-05-2010 02:59 PM |