Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Using autotext in MSO 2013

    I am wishing to insert blocks of text saved as building blocks (autotext) into a document based on the result attached to a variable bookmark
    cheers

    Phil Carter

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Do you need code to get started?
    Code:
    Sub Macro1()
      Dim rng As Range
      If ActiveDocument.Bookmarks.Exists("Hello") Then
        If ActiveDocument.Bookmarks("Hello").Range.Text = "Hi" Then
          Set rng = ActiveDocument.Range
          rng.Collapse wdCollapseEnd
          ActiveDocument.AttachedTemplate.BuildingBlockEntries("MyBB").Insert Where:=rng, RichText:=True
        End If
      End If
    End Sub
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,048
    Thanks
    124
    Thanked 119 Times in 116 Posts
    You can also use an IF field to test for the value of the bookmark. The true text can be an AutoText field.

    You question's title is about Microsoft Office. AutoText and building blocks are available in Word. I do not know that they are available in other Office applications. AutoCorrect is available in most Office applications. Automated Boilerplate Using Microsoft Word.
    Charles Kyle Kenyon
    Madison, Wisconsin

  4. #4
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts
    Charles hi
    Can't seem to get this to work.
    Bookmarks.JPG
    cheers

    Phil Carter

  5. #5
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,048
    Thanks
    124
    Thanked 119 Times in 116 Posts
    Try attaching the document rather that a picture of it.

    There is no good reason to nest your IF fields. It can cause problems if you nest too deep. I do not know what too deep is, but believe it is 16 levels. If each IF field simply has truetext it will only give results if there is a match.
    Charles Kyle Kenyon
    Madison, Wisconsin

  6. #6
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts
    The document (attached) is one to test the bookmark outputs from our CRM.

    The bookmark used for the IF statement is the sixth on the page I have also tried to use this for the REF field.
    Attached Files Attached Files
    cheers

    Phil Carter

  7. #7
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,048
    Thanks
    124
    Thanked 119 Times in 116 Posts
    You have a bunch of nested IF fields with no truetext.
    Start with simple IF fields. One test, one result.

    Once you have those tests working, then try nesting.
    Last edited by Charles Kenyon; 2015-05-04 at 07:59.
    Charles Kyle Kenyon
    Madison, Wisconsin

  8. #8
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Phil

    It looks like your bookmarks are insertion points and contain no text. You will need content in your bookmark if you want to test the contents of that bookmark.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  9. The Following User Says Thank You to Andrew Lockton For This Useful Post:

    bonriki (2015-05-06)

  10. #9
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts
    Andrew
    I think I understand what you are saying but not sure how to apply it.
    This is the xml code used in our CRM for extracting data and placing it at the bookmark bmk010ProgrammeType in a report template,

    <content type="expression" id="bmk010ProgrammeType" locationtype="bookmark" locationname="bmk010ProgrammeType" function="insertafter" value="Trim(AU.Program.ProgramMaster.Description)" object="objAUJob" />

    Is it the function that I have highlighted that needs to be changed?
    cheers

    Phil Carter

  11. #10
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts
    Andrew
    That is correct they are only placeholders until the document is merged from the CRM. It is then that I want to use the results to compare and insert Autotext based on the result
    cheers

    Phil Carter

  12. #11
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    What code do you have? It is not overly dramatic to get the contents of a paragraph where the bookmark resides.
    ActiveDocument.Bookmarks("Hello").Range.Paragraphs (1).Range.Text - or something similar

    The fact that there is an xml attribute that specifies "insertafter" could imply that there is another option to "insertbefore" or "insertinto". We would need to see the code or do testing to know.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  13. #12
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts
    Andrew
    I am trying to do it without using any code in the template
    cheers

    Phil Carter

  14. #13
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    In that case you need to contact your CRM supplier - we can't help you here.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  15. #14
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts
    Andrew a final question for you
    If I place the bookmark, bmk010ProgrammeType, inside another bookmark, bmkTest, and using the REF field { REF bmkTest }, shouldn't this return the value of bmk010Programmetype?
    cheers

    Phil Carter

  16. #15
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Yes
    Andrew Lockton, Chrysalis Design, Melbourne Australia

Page 1 of 2 12 LastLast

Posting Permissions

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