Consulting

Results 1 to 10 of 10

Thread: Privately Identifying Custom Text in a Document

  1. #1
    VBAX Contributor
    Joined
    Aug 2012
    Posts
    120
    Location

    Privately Identifying Custom Text in a Document

    I have a VBA project that compiles lengthy documents using templates. Often the templates are customized (User-specific information is added, or text is deleted that doesn't apply to the User).

    I'd like to be able to track the custom text in some way that it can easily be identified by VBA code but without the tracking mechanism being visible to the reader.

    I was thinking Fields might be the way to go, but I thought I would ask the Forum users what the best way to achieve that would be?

  2. #2
    My first suggestion would be a style (paragraph or character style, as necessary) that doesn't change the formatting of text that it's applied to. In code, an objRange.Find can locate the style.

  3. #3
    VBAX Contributor
    Joined
    Aug 2012
    Posts
    120
    Location
    Thanks for your response.

    One of the issues for me on this when it comes to Styles is that it has to be a Normal Style. I pull these templates from separate Word documents and compile them into the finished document using:

    Selection.InsertFile FileName:=FileSourceName, Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False

    If the Style of the source document isn't, "Normal," the font can/will likely be inconsistent in the finished document. I'm not sure why that is, but the source document Style has to be, "Normal" according to my understanding so it's uniform in the finished document. That's something someone on this forum taught me and it definitely seems to be true.

    I'm not sure it would work the way you suggest because I'm thinking the Style couldn't be, "Normal" under the method you suggest. I could definitely be wrong about that, though.

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Not sure I completely uderstand, but see if Document Variables would work

    https://support.microsoft.com/en-us/...word-documents
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by Mavila View Post
    I have a VBA project that compiles lengthy documents using templates. Often the templates are customized (User-specific information is added, or text is deleted that doesn't apply to the User).
    That suggests you're not actually using a Word template. In any event, even if you're using some kind of base document, Word's document compare tools should be sufficient to show all the changes between a given template/base document and the edited version. Such comparisons can be done with VBA.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  6. #6
    VBAX Contributor
    Joined
    Aug 2012
    Posts
    120
    Location
    Paul,

    Using Selection.InsertFile, if the incoming file's text isn't in Normal style, the font can get changed after it's inserted for some reason. I'm not sure why that happens, but it does. For example, I tend to prefer Times New Roman size 10 and if the incoming file's text isn't in Normal style, it has a tendency to get converted to something else like Arial, for instance.

    Thanks for the tip on Document Variables. I'll check it out.

  7. #7
    VBAX Contributor
    Joined
    Aug 2012
    Posts
    120
    Location
    macropod,

    Thank you. You're absolutely correct. None of the documents used are technically template type documents. I just call them that because the content is something of a template.

    I'm not sure your suggestion would be optimal. There are two kinds of modifications that are typically made to the base document before being inserted into the target plan document. One would be to cut out portions of the template that are not applicable to the user. I hadn't really thought of tracking that kind of edit, frankly. I'll have to give that some thought because it could be useful.

    The second type of modification would be the addition of something very specific to the user's business operations such as an address, a department name, or a specific piece of equipment, tool or process. These are the kinds of edit's I'd be most interested in tracking.

    I'll give your suggestion some more thought. Thank you.

  8. #8
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Word's document comparison function will report both kinds, plus formatting changes, etc.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  9. #9
    VBAX Contributor
    Joined
    Aug 2012
    Posts
    120
    Location
    I have limited experience with the Compare function/method and have never done it using VBA.

    I'm not sure it would work well with what I'm trying to achieve. Imagine a Master Document that contains 30 or 40 chapters that is assembled with the use of Selection.InsertFile for each chapter (30-40 separate documents that represent a chapter). Each insertion is a new section in the Master.

    The first issue, I believe, would be the fact that I would have to open the Chapter document to conduct the comparison. That brings some performance issues, not that I'm looking for lightning fast performance.

    The second issue is that I'm comparing a Master document of 30-40 Chapters with a single Chapter, so I don't know that this would be manageable unless I could compare the Chapter document to a selection in the Master. Is that even possible - comparing text selections, ranges, or sections in two different documents (as opposed to the entirety of each document)?

    Additionally, the comparison probably would have to be done between the Chapter template and the User's modified version of the Chapter, then inserted into the Master. I kind of want to track it inside the Master, but I'm not sure that's necessary.

  10. #10
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Perhaps you should actually try using the Document Compare tool manually - via Review>Compare.

    Yes, the comparison between a single-chapter master and an final of 30+ chapters will report all the differences, but its not apparent how else you would have Word conduct a comparison with VBA and not have to deal with all that extraneous data. Of course, if you know which chapter you want to compare with the master, you could just extract the relevant chapter to a new document and compare that.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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