Share via

MS Word Forms - PullAutoText error - Insert AutoText depending on result of legacy drop-down field

Anonymous
2020-09-08T19:09:00+00:00

I'm attempting to update a series of forms created by a retired employee. In the following drop-down box we have these listings. 

If I try to edit the list by removing and adding, or simply adding a listing I get this error message:

This is the only VBA code I can find:

Public Sub PullAutoText()

   Dim t As Table, iCtr As Integer, szEntry As String, szName As String

   Application.ScreenUpdating = False

   With ActiveDocument

      Set t = .Tables(2)

      t.Cell(1, 1).Range.Delete

      For iCtr = 1 To 11

         szName = "Exempt" + Format(iCtr, "0")

         If (Trim(.FormFields(szName).Result) <> "") Then

            szEntry = .FormFields(szName).Result

            If (InStr(1, szEntry, Chr(167)) > 0) Then

               If (Left(szEntry, 1) = Chr(167)) Then

                  szEntry = Mid(szEntry, 2)

               Else

                  szEntry = Right(szEntry, 5)

               End If

            End If

            .AttachedTemplate.AutoTextEntries(szEntry).Insert Where:=.Range(t.Cell(1, 1).Range.End - 1, t.Cell(1, 1).Range.End - 1)

            .Range(t.Cell(1, 1).Range.End - 1, t.Cell(1, 1).Range.End - 1).InsertAfter " "

         End If

      Next iCtr

      t.Columns.AutoFit

   End With

   Application.ScreenUpdating = True

End Sub

I have about a dozen forms setup this way and I thought I'd post this question before rebuilding everything. Any advice or comments here would be most appreciated. 

Thanks in advance!

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

15 answers

Sort by: Most helpful
  1. Anonymous
    2020-09-08T21:22:12+00:00

    Thanks Charles. I'm working on posting but there's a lot (logo, contact numbers etc.) that I have to remove. I had it done and accidentally removed xml info, not realizing that was the VBA code! I should have it soon. I REALLY appreciate your help on this!

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2020-09-08T21:13:48+00:00

    Hi Jeff,

    Sorry, our responses crossed paths. The best forum would be the Microsoft Word - Programming forum. If you can post the template, I can probably solve this this afternoon. Otherwise, I can move it to that forum for you.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2020-09-08T20:13:20+00:00

    Troubleshooting this would be easiest with access to the template this is based on. If you want, save a sample template with the problem on OneDrive or Dropbox and paste a view link here. Remove any confidential or sensitive information first. I or someone else can take a look at it. You can use the Rand function in Word to generate random text if you need to. See Suzanne Barnhill's article at http://wordfaqs.ssbarnhill.com/DummyText.htm.

    For OneDrive: See https://support.office.com/article/share-onedri...

    For DropBox: See https://help.dropbox.com/files-folders/share/vi...

    https://answers.microsoft.com/en-us/windows/for...

    We can do it without a sample, but it will take longer, at least for me. I would essentially have to recreate what you are doing, blind, from scratch. My assumptions will probably be wrong, resulting in us going back and forth to find an answer.

    I can confirm that if you are working with a Word file then your guess that this is the problem code is correct.

    Here is my writing page dealing with using vba with AutoText and Building Blocks. It became more difficult when Building Blocks were added to Word.

    http://www.addbalance.com/usersguide/autotextau...

    If you are redoing Word forms, legacy form fields like this were essentially replaced by Content Controls beginning in 2007. Content Controls are much more flexible and powerful. You might want to consider switching to those.

    http://gregmaxey.com/word_tip_pages/content_con...

    If you want to do such a conversion, there are free utilities available that can change legacy formfields to Content Controls.


    These are links to pages on one or more pages on my website and on trusted Word MVP website(s). Those pages contain accurate safe information that I think will help you. However, as an Independent Advisor I am required to give the following notice when providing non-Microsoft links, even to my own site :


    Required Notice: This is a non-Microsoft website. The page appears to be providing accurate, safe information. Watch out for ads on the site that may advertise products frequently classified as a PUP (Potentially Unwanted Products). Thoroughly research any product advertised on the site before you decide to download and install it.


    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2020-09-08T20:00:06+00:00

    Yes, Charles, you are correct. This is a form created by MS Word. My apologies. Where should I post the question?

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2020-09-08T19:51:26+00:00

    Hi Jeff,

    Unfortunately, you posted this in the unfortunately named "Forms" forum. That forum is for the Microsoft Forms application.

    This looks like a program from Word, to be called upon exit from your drop-down list. If I am correct in this, please let me know. If I'm wrong, someone else will have to help you because I really know little about the Forms application.

    This forum is a user-to-user support forum. I am a fellow user.

    I hope this information helps.

    Please let me know if you have any more questions or require further help.

    You can ask for more help by replying to this post (Reply button below).

    Stay well

    Was this answer helpful?

    0 comments No comments