Link to home
Start Free TrialLog in
Avatar of mvp1985

asked on

How to select first form field of newly pasted part of document automatically with macro

So I have a great macro that unprotects a document, goes to the end of the document, pastes an autotext, and then reproects the document. However, I need to manually  tab through the form fields in order to get to the newly inserted part. So here my question: How do I get the macro to automatically advance to the first form field of the newly pasted part once I run the macro?

Here is my current macro:

Sub Macro3a()
    Dim aDoc As Document
    Dim strPassword As String
    strPassword = ""
    Set aDoc = ActiveDocument
    If aDoc.ProtectionType <> wdNoProtection Then
        aDoc.Unprotect strPassword
    End If
    Application.Templates(aDoc.AttachedTemplate.FullName). _
        BuildingBlockEntries("Schätzung 1").Insert Where:=aDoc.Bookmarks("\EndOfDoc").Range
    aDoc.Protect Type:=wdAllowOnlyFormFields, Password:=strPassword
 End Sub
Avatar of FarWest

try this
Avatar of Rgonzo1971

pls try


Avatar of mvp1985


None of these work, since the suggested sollutions selects the very first form field of the document on the first page. However, I need the form field selected that is the first one that I just pasted.
Ok, you can add a bookmark before doing the insertion and then move back to that bookmark
Avatar of Rgonzo1971

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Are you sure that you understand the normal use of form fields?

The idea is that you design the document manually,  placing form fields in places where the text might  be changed by the user. By default , each form field is bookmarked (Text1, Text2, etc). The bookmark name becomes the form field name.You then protect the document for forms.

The user can then only change the text in the form fields. It can be done programatically without removing the protection:
ActiveDocument.FormFields("Text1").Result = "some new text"

Open in new window