Solved

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

Posted on 2014-11-24
6
122 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 12

Expert Comment

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

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
Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

 
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 52

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Suggested Courses

622 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