Solved

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

Posted on 2014-11-24
6
112 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 48

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 48

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
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:
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…

708 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

14 Experts available now in Live!

Get 1:1 Help Now