Solved

How to protect or recreate word bookmarks through VBA

Posted on 2008-09-29
6
969 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
[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
  • 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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.

Question has a verified solution.

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

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…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

628 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