Checking for bookmark

L

Lee

How do I get a template to check for a bookmark (or a
variable, or text etc) and if it is present, run a
userform? Once the userform has been filled in, I want to
delete this once user has clicked OK.
 
J

Jay Freedman

Lee said:
How do I get a template to check for a bookmark (or a
variable, or text etc) and if it is present, run a
userform? Once the userform has been filled in, I want to
delete this once user has clicked OK.

To check for the bookmark named "start", use the code

If ActiveDocument.Bookmarks.Exists("start") Then
MyUserForm.Show
End If

I'm not sure what you mean by "delete this" -- what is "this"?
 
L

Lee

I want to delete the bookmark (or variable or bit of text)
that it searches for... The reason being - I have MS Word
2002 templates running through a document management
system and it runs the VBA code everytime it is opened. I
do not want it to do this, I only want the coding to run
when a new version is created (long story so I will not
get into it).
So what I want to do is have something the VBA code can
look for within the document, and if found, then run the
userform... but once the userform has been run and the
user has clicked OK, I want the coding to find
that "something" and delete it (so when someone opens the
document that is already filled in, the userform won't
show asking for the name, address, details of letter etc).
Understand?? Kinda confusig without getting into how our
document management system runs...
Thanks
 
J

Jay Freedman

Hi Lee,

Well, that's why I asked. If you want code to run only when a new
document is created based on your template, you name the macro either
AutoNew() in a regular module or Document_New() in the ThisDocument
module. Then you don't have to worry about finding and deleting
bookmarks.

See http://word.mvps.org/FAQs/MacrosVBA/DocumentEvents.htm for more
info.
 
L

Lee

Our Document Management system (DMS) doesn't quite work
that way. It's not so straight forward as that. When the
DMS creates a new document based on a template, it creates
a version then edits the document so we have to have a
special command line in the Edit command of the DMS to run
the coding. If you need to edit the document again, it
runs the coding but I only want the coding to run when a
new document is generated based on the template. It's
very confusing.

The only way around the coding not running again when
someone wants to edit the document again is to have
something in the template that is deleted once the user
fills in the userform (the first time).

Never mind - I'll work it out myself as it's very
confusing due to the templates being run via a Document
Management System.

Thanks for your help anyway
-----Original Message-----
Hi Lee,

Well, that's why I asked. If you want code to run only when a new
document is created based on your template, you name the macro either
AutoNew() in a regular module or Document_New() in the ThisDocument
module. Then you don't have to worry about finding and deleting
bookmarks.

See
http://word.mvps.org/FAQs/MacrosVBA/DocumentEvents.htm for
more
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Lee > écrivait :
In this message, < Lee > wrote:

|| Our Document Management system (DMS) doesn't quite work
|| that way. It's not so straight forward as that. When the
|| DMS creates a new document based on a template, it creates
|| a version then edits the document so we have to have a
|| special command line in the Edit command of the DMS to run
|| the coding. If you need to edit the document again, it
|| runs the coding but I only want the coding to run when a
|| new document is generated based on the template. It's
|| very confusing.
||
|| The only way around the coding not running again when
|| someone wants to edit the document again is to have
|| something in the template that is deleted once the user
|| fills in the userform (the first time).

Use a custom Boolean property. Set its value to False and change it to true
once the userform runs. Then, in your code, always check for the value of
the said property. If it is true, do not run the code.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top