Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to protect or recreate word bookmarks through VBA

Posted on 2008-09-29
6
Medium Priority
?
989 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 2000 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: 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.

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

783 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