• Using autotext in MSO 2013

    Author
    Topic
    #499741

    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

    Viewing 9 reply threads
    Author
    Replies
    • #1502556

      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
    • #1502629

      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.

    • #1502847

      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.

      • #1502865

        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.

    • #1502871

      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.

      • #1507849

        Charles
        Can I get you to look at the attached document with IF fields that I can’t seem to get to work, it’s driving me nuts!

        • #1508350

          Charles
          Can I get you to look at the attached document with IF fields that I can’t seem to get to work, it’s driving me nuts!

          You need to nest an AutoText Field as your truetext.
          { Autotext “Chem” }

    • #1502872

      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.

      • #1503198

        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,

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

      • #1503207

        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

    • #1503219

      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.

    • #1503233

      Andrew
      I am trying to do it without using any code in the template

    • #1503310

      In that case you need to contact your CRM supplier – we can’t help you here.

    • #1503490

      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?

    • #1503530

      Yes

      • #1505138

        Sorry for the delay been away for 7 days.

        Doesn’t seem to work

    Viewing 9 reply threads
    Reply To: Using autotext in MSO 2013

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: