Solved

add bookmark label to 78 documents

Posted on 2016-08-10
2
64 Views
Last Modified: 2016-08-10
i have a folder which has over 200 word documents  set up as a form with various bookmarks in them that will extract info from the documents to a 3rd party applicaiton. The person who made the form forgot to label one bookmark in 78 documents that have the information in the form, but the bookmark has to be added to extract the info in the field. what has to be done is this: unprotect the document, go to the book mark, add the label, protect the documents, save it, and go on to number 2. Is there a way to add the bookmark to these 78 documents in a more efficient manner? this is word 2013 on windows 7.
0
Comment
Question by:geriatricgeek
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 41750995
You could run a VBA macro like this.
Sub AddLabel()
    Dim strFile As String
    Dim doc As Document
    Dim strInfolder As String
    Dim strOutfolder As String
    Dim strLabelText As String
    Dim strBookMarkName As String
    Dim rng As Range
    
    'One off, so hard code the input data
    strInfolder = "C:\My Documents\In"
    strOutfolder = "C:\My Documents\Out"
    strBookMarkName = "MyBookmark"
    strLabelText = "Some text"
    
    strFile = Dir$(strInfolder & "*.docx*")
    Do Until strFile = ""
        Set doc = Documents.Open(strInfolder & "\" & strFile)
        doc.Unprotect 'password
        Set rng = doc.Bookmarks(strBookMarkName).Range
        rng.Text = strLabelText
        doc.Bookmarks.Add strBookMarkName, rng 're-add bookmark in case it was overwritten
        doc.Protect wdAllowOnlyFormFields, True ',password
        doc.SaveAs strOutfolder & "\" & strFile
        doc.Close wdDoNotSaveChanges
        strFile = Dir$()
    Loop
    
End Sub

Open in new window


It isn't entirely clear what the relationship between the bookmark and the label is. This macro will replace the contents (if any) of the bookmark with the given text. If this is not correct, we will need some more details.
0
 
LVL 1

Author Closing Comment

by:geriatricgeek
ID: 41751375
Looks intense. I'll give it a try. thanks
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles a…

791 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