Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-22-2013, 10:56 AM
tng tng is offline Replace text of textboxes Windows 8 Replace text of textboxes Office 2010 64bit
Novice
Replace text of textboxes
 
Join Date: Dec 2013
Posts: 1
tng is on a distinguished road
Default Replace text of textboxes


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
Reply With Quote
  #2  
Old 12-22-2013, 05:23 PM
macropod's Avatar
macropod macropod is offline Replace text of textboxes Windows 7 32bit Replace text of textboxes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace text of textboxes Macro to find text and replace with form field containing that text iiiiifffff Word VBA 16 06-04-2016 01:47 AM
Replace text of textboxes 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
Replace text of textboxes Select all textboxes in Word document msword270 Word 1 01-12-2012 11:41 AM
Replace text of textboxes Many textboxes on top of each others? Giygas PowerPoint 1 12-05-2010 02:59 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:44 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft