Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-20-2011, 10:09 AM
webharvest webharvest is offline Update bookmarks and variables in document Windows Vista Update bookmarks and variables in document Office 2007
Novice
Update bookmarks and variables in document
 
Join Date: Jun 2011
Posts: 6
webharvest is on a distinguished road
Default Update bookmarks and variables in document

I have a user form that I use to put information into bookmarks and docvariables. When I insert the text from the userform into a bookmark I do the following to reestablish the bookmark.

Code:
pStr = Replace(.PropName.Value, Chr(10), Chr(10) + Chr(9))
Set oRng = ActiveDocument.Bookmarks("PropName").Range
oRng.Text = pStr
ActiveDocument.Bookmarks.Add "PropName", oRng
The above code works great but here is my problem. When someone creates a new document from my template the user form comes up and everything is entered but I give the user the rights to update the word document after the form populates everything. So what I am seeing happen is the person goes to change the Proposal Name (PropName bookmark in the document) and since there are no spaces before or after the bookmark text they end up deleting the bookmark when they type the new name in. I believe this is because when you select the whole text it automatically selects the bookmark tags so when you start typing the new text the book mark is deleted.

1) So the best solution would be if I can somehow protect a bookmark from being deleted when inside the document but unlock it when I run the vba code above.


2) An alternative solution would be to add several spaces at the end of the text inside the bookmark when the above vba code creates the bookmark. This would make it harder to select everything and delete the bookmark.

I would like to make it impossible but I will take what I can get.

Thank you ahead of time.
Reply With Quote
  #2  
Old 06-20-2011, 05:15 PM
macropod's Avatar
macropod macropod is offline Update bookmarks and variables in document Windows 7 64bit Update bookmarks and variables in document Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi webharvest,

So why are the users allowed to edit things like the Proposal Name other than through the userform? Bookmarks are fragile. So, instead of using bookmarks, I'd suggest having your code maintain/update custom document properties with the data and use DOCPROPERTY fields where required to replicate the data.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-20-2011, 08:10 PM
webharvest webharvest is offline Update bookmarks and variables in document Windows Vista Update bookmarks and variables in document Office 2007
Novice
Update bookmarks and variables in document
 
Join Date: Jun 2011
Posts: 6
webharvest is on a distinguished road
Default

Well my initial thought was I would just use the userform to make the creation of the document easier and then let the person edit the document as normal after the initial creation. I initially thought this way because the people doing this work are not very computer savvy and I figured I would get less resistance.

When you say docproperties do you mean document variables? If so I am using them in some places of the userform.

Okay so lets say I do only allow the person to change these variables via the userform; I have a couple questions
1) Right now I only call up the userform when a new document is created from the template. What is a clean way to have the userform pop back up when the user wants to change something? I thought about a macro button but we have to print or make pdfs to send out to people and I don't want the button to show up in the final document.
2) What is the right way to lock down all the docvariables and/or book marks but still let the user modify the rest of the document? There is a lot of text that needs to be document specific so I have to let the user change some things.

Thanks
Reply With Quote
  #4  
Old 06-21-2011, 12:51 AM
macropod's Avatar
macropod macropod is offline Update bookmarks and variables in document Windows 7 64bit Update bookmarks and variables in document Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi webharvest,
The best approach might be to configure the document as a Word form with a combination of protected and unprotected Sections, delineated by continuous or next-page Section breaks.

In the protected Section(s), you would have formfields into which the users could input data (eg the Proposal Name) only. Anything else in a protected Section would be inaccessible. If the same data that is to be input into a formfield appears in multiple places, you could set the formfield properties to 'calculate on exit' and have cross-references at the other locations, all pointing to the formfields' internal bookmark names.

In the unprotected Section(s), you'd have any content that the users are allowed to edit.

See attached document.
Attached Files
File Type: doc Form Demo.doc (32.0 KB, 34 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 06-21-2011, 06:01 AM
webharvest webharvest is offline Update bookmarks and variables in document Windows Vista Update bookmarks and variables in document Office 2007
Novice
Update bookmarks and variables in document
 
Join Date: Jun 2011
Posts: 6
webharvest is on a distinguished road
Default

That sounds like a good approach. But I do have a couple of questions

1) Is there a good way to call up the userform after the initial creation of the document? Right now in your example doc if the person clicks on the protected area they would have no way of knowing they can only change that field by opening the userform.
What would be ideal is when the person clicks on the protected text the userform automatically opens. Another alternative is when the user clicks on the protected text a note pops up telling the user how to open the userform.

2) The problem is I don't want to put a macro button on the page because won't that show up when the document is printed?

3) If the section is protected and info can only be put in via the form do I need to turn protection off and then turn it back in VBA when the form goes to enter the update? What is the code for that?

Thanks
Reply With Quote
  #6  
Old 06-21-2011, 03:22 PM
macropod's Avatar
macropod macropod is offline Update bookmarks and variables in document Windows 7 64bit Update bookmarks and variables in document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi webharvest,

With the approach I suggested, you wouldn't need a userform. When you open such a document, it will position the cursor at either: a) the first formfield if there is one in the first (protected) Section; or b) at the start of the document otherwise. Also, no macros are required for this approach, which obviates any macro security issues and the risk that users will choose to disable the macro that drives your userform upon opening. I think your third question is based on a misunderstanding. As you'll see from the document I posted, the cross-reference updates immediately you tab out of the first formfield. No vba is required. If you have more than one formfield in the protected section, tabbing out of one automatically takes you to the next one.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
bookmarks, protect bookmarks



Similar Threads
Thread Thread Starter Forum Replies Last Post
Table of Contents does not update, when document is opened on other computer jaybo Word 1 01-25-2011 04:56 PM
Update Document Template when Saving the Document File bjbercaw Word 3 11-16-2010 02:03 PM
Bookmarks for a PDF? Ownaholic Word 0 10-30-2010 12:27 AM
Using bookmarks in a protected document Bill Stemp Word 0 10-16-2010 06:47 AM
Envelopes with Document Variables mailtobln Word 0 02-11-2009 10:48 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:21 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft