Solved

How to protect or recreate word bookmarks through VBA

Posted on 2008-09-29
6
946 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
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:

809 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