Solved

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

Posted on 2014-11-24
6
114 Views
Last Modified: 2014-11-26
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
0
Comment
Question by:mvp1985
6 Comments
 
LVL 12

Expert Comment

by:FarWest
ID: 40463927
try this
ActiveDocument.Fields(1).Select
0
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 40463931
Hi,

pls try

aDoc.FormFields(1).Select

Regards
0
 

Author Comment

by:mvp1985
ID: 40463966
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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Expert Comment

by:FarWest
ID: 40463971
aha,
Ok, you can add a bookmark before doing the insertion and then move back to that bookmark
0
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 40463989
Hi,

pls try

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

Open in new window

Regards
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40464167
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

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now