Solved

How to protect or recreate word bookmarks through VBA

Posted on 2008-09-29
6
941 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
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:
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.

746 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now