Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Dec 2001
    NY, USA
    Thanked 0 Times in 0 Posts

    Mass Search/Replace of INCLUDETEXT field (any, really)

    Hi - I've been given a collection of files used in a fairly complex MailMerge application that each contain a series of INCLUDETEXT field references to other files in the collection, and asked to come up with a way to distribute these to folks. Currently, these file references all point to "A:" for simplicity's sakes when running on a new PC. Obviously not the best solution (for speeds sake, at least) - I was thinking of building an installation program (in VB, or InstallShield, etc) to handle mass editing of these references based on a user-specificied location. But it appears that Word doesn't like having other external programs edit DOC files (since I get a "can't open this file" error after editing the DOC file using an external editor/programming language). I'm assuming this is something I could do from WordBasic, or maybe VB? Does anyone have any suggestions of where to get started?

    Thanks very much,
    Jim Carter

  2. #2
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Sun Prairie, Wisconsin, Wisconsin, USA
    Thanked 125 Times in 120 Posts

    Re: Mass Search/Replace of INCLUDETEXT field (any, really)

    Which version of Word?

    It is never, ever a good idea to have Word work with anything on the A: drive directly. It scrambles such documents.

    It may be possible to have the path to the other documents set as a custom document property. (There is a built-in property for this but it changes all hyperlinks within the document.) That path could then be put into the IncludeText fields using a DocProperty field. Document properties like this can be accessed and changed without opening the document (and probably without opening Word). See the <A target="_blank" HREF=> MVP FAQ site</A>'s VBA FAQ on document properties and VBA for more on this.
    Charles Kyle Kenyon
    Madison, Wisconsin

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Melbourne, Victoria, Australia
    Thanked 279 Times in 256 Posts

    Re: Mass Search/Replace of INCLUDETEXT field (any, really)

    As Charles says, you can change the document properties without opening Word and therefore don't necessarily need to rely on VB or VBA to modify them.

    I would store all of the IncludeText filepaths as a document property and then nest fields to get the path from the document property. The nested fields would look something like this
    <pre>{Includetext "{DocProperty "Category"}Doc1.doc"}</pre>

    where the document property category contained the path (with the usual silly modifications) such as C:Work
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 94 Times in 90 Posts

    Re: Mass Search/Replace of INCLUDETEXT field (any, really)

    A VBA routine, without a user interface to gather a path, would look like this. Because it works on the active document and manipulates Word-specific properties, running this from outside Word would require opening Word in the background (I think).
    <pre>Sub UpdateIncludeTextPath()
    Dim aField As Field
    For Each aField In ActiveDocument.Fields
    If aField.Type = wdFieldIncludeText Then
    aField.Code.Text = Replace(aField.Code.Text, "a:", "c:my dir", _
    , , vbTextCompare)
    End If
    End Sub</pre>

    Note: the Replace function was added in VB6 (Word 2000). Prior to Word 2000, you had to use the cumbersome technique of finding each instance of the string with InStr, and then concatenating the other parts around the replacement string.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts