Solved

How to protect or recreate word bookmarks through VBA

Posted on 2008-09-29
6
953 Views
Last Modified: 2012-05-05
I have a word template that I am creating.  The user opens word, a userform pops up and asks them to fill in several text boxes.  After submitting, the text boxes populate word bookmarks, including bookmarks in the header of the file.  This all works correctly.  However, if the user then changes one of the values and deletes the bookmark then I have a problem.
After the values are populated, I can run a macro to send those bookmark values to an access database.  If the bookmark is deleted then I get an error when submitting to the database.
I would like to know how to either protect the bookmarks from deletion or somehow add them back if they are modified and deleted.
0
Comment
Question by:pattersonr
  • 3
  • 3
6 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 22597913
It sounds as if you need to use a document form with Forms protection and to put the text into Form Fields.
0
 
LVL 1

Author Comment

by:pattersonr
ID: 22598090
Graham..
I tried forms protection...but the way that I wanted to design the form it didnt work well.  It probably says more about my skill level than anything else.  Let me sanitize my document and I will attach it so you can see in a bit more detail.
I think it had to do with the fact i want information in the header and the fact that I wanted to be able to reference the areas of the document to add to the database.  The only way I could figure out to reference specific areas for the database piece was with bookmarks.
Thanks for the help
TestDoc.doc
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 22598764
I see that you are using tables. You could locate the data in an individual cell instead of using the bookmark.


Function getCellText(iTable As Integer, iRow As Integer, iCol As Integer) As String
    Dim rng As Range
    Dim tbl As Table
    
    Set tbl = ActiveDocument.Tables(iTable)
    Set rng = tbl.Cell(iRow, iCol).Range
    rng.MoveEnd wdCharacter, -1
    getCellText = rng.Text
End Function

Open in new window

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:pattersonr
ID: 22600645
Graham,

That is actually a very good idea.  I actually took a variation of that to fix my problem.  I wrote some code to find the values in the cells and if a bookmark had been deleted, then on save recreate the bookmark.  You method would eliminate that step.  I already have the template in the wild so to speak.  But I probably will alter it based on your suggestion.  Thank you for your help.

0
 
LVL 1

Author Closing Comment

by:pattersonr
ID: 31501237
Thank Graham
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 22601262
Thanks. Good luck with the project.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

There is a feature provided by MS Word that lets you create an Table of Contents for your Word document automatically. To use this feature for other documents there are two steps involved,   1.  Prepare your document for a table of contents (he…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

680 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