none
Macro help RRS feed

  • Question

  • I have the following macro that I am having problems with. It works fine if I run it straight from Word. But when I embed the template into our program it won’t recognize the AutoTextEntries. What I am trying to do is if the checkbox in my form is true them change the symbol in my bookmark to a box with an ‘x’ in it. (This would be Font:="Wingdings", CharacterNumber:=253).

    For i = 1 To 11

      Set oRng = ActiveDocument.Bookmarks("CB" & i).Range

      If Me.Controls("Ck" & i).Value = True Then

        ActiveDocument.AttachedTemplate.AutoTextEntries("CB").Insert Where:=oRng, RichText:=True

       oRng.Font.Color = wdColorBlack

        oRng.Font.Size = 14

      Else

        ActiveDocument.AttachedTemplate.AutoTextEntries("UCB").Insert Where:=oRng, RichText:=True

        oRng.Font.Color = wdColorAutomatic

        oRng.Font.Size = 12

      End If

      ActiveDocument.Bookmarks.Add "CB" & i, oRng

    Next i

    Saturday, August 16, 2014 12:18 AM

Answers

  • You where correct Graham. I had lost the link to the main template. Once I reconnected to the template it works fine.

    Thanks for your help.

    • Marked as answer by fuzzhead58 Tuesday, September 9, 2014 5:35 AM
    Tuesday, September 9, 2014 5:35 AM

All replies

  • The problem almost certainly relates to 'ActiveDocument.AttachedTemplate.AutoTextEntries'

    Where EXACTLY are the autotext entries stored?


    Graham Mayor - Word MVP
    www.gmayor.com

    Saturday, August 16, 2014 4:48 AM
  • I thought they are stored in the template.
    Saturday, August 16, 2014 12:52 PM
  • They are, but which template? If they are stored in the normal template, then they will not be available to documents created from another template (when you are specifying the attached template). Ensure that they are stored in the document template that the documents are being created from.

    The document can only use building blocks it has access to.

    You will find example code for addressing all the building block locations at http://www.gmayor.com/word_vba_examples_3.htm


    Graham Mayor - Word MVP
    www.gmayor.com

    Saturday, August 16, 2014 1:18 PM
  • I'll look at that this morning and make sure they are in the template. Thanks for your support.
    Saturday, August 16, 2014 1:28 PM
  • You where correct Graham. I had lost the link to the main template. Once I reconnected to the template it works fine.

    Thanks for your help.

    • Marked as answer by fuzzhead58 Tuesday, September 9, 2014 5:35 AM
    Tuesday, September 9, 2014 5:35 AM