Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
|
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 27th, 2007, 12:03 PM
Registered User
 
Join Date: Sep 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Replacing text in text box inside table

As we've moved company locations, I want to replace the street address on a large number of documents, all in the same folder. I've written code to replace the appropriate text throughout all the docs in the specified folder. It works just fine (main text, headers, footers, etc.), except for a text box that's inside a table cell. (I set up the cover of each doc as a 1 row x 3 column table. In cell(1,1), I have a text box that has the company's address.) Code follows - can anyone see what's wrong? This is driving me crazy(er).

Many thanks!

Larry

Sub FindReplaceAllDocsInFolder()
Dim I As Integer
Dim doc As Document
Dim rng As Range
Dim strFilePath As String
Dim intFilesFoundCount As Integer

With Application.FileSearch
    .LookIn = "c:\Test"
    .SearchSubFolders = False
    .FileType = msoFileTypeWordDocuments
    If Not .Execute() = 0 Then
        For I = 1 To .FoundFiles.Count
            Set doc = Documents.Open(.FoundFiles(I))
            Set rng = doc.Range
                For Each rng In doc.StoryRanges
                    With rng.Find
                        .ClearFormatting
                        .Replacement.ClearFormatting
                        .Text = "111 West 5th"
                        .Replacement.Text = "2448 East 81st"
                        .Forward = True
                        .Wrap = wdFindContinue
                        .Format = False
                        .MatchCase = False
                        .MatchWholeWord = False
                        .MatchWildcards = False
                        .MatchSoundsLike = False
                        .MatchAllWordForms = False
                        .Execute Replace:=wdReplaceAll
                    End With
                Next rng

            doc.Save
            doc.Close

            Set rng = Nothing
            Set doc = Nothing
        Next I
    Else
        x = MsgBox("No files matched " & .FileName, vbOKOnly, "No Files Matched")
    End If
End With

End Sub


Larry Landis
Technical Writer





Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting inside Rich Text Box bettiahamit .NET Framework 3.5 1 November 10th, 2008 06:04 AM
Text Box .text Property Displays conflicting Valus JPOhlman Visual Basic 2005 Basics 3 August 23rd, 2006 02:39 PM
insert text into a text box by selecting an link gavmc Other Programming Languages 0 February 15th, 2006 09:46 AM
Changing between bold and plain text in a text box funkybuddha Access 2 January 3rd, 2006 10:15 AM
Extract text from text file & put in dropdown box tsukey Beginning PHP 5 July 20th, 2004 09:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.