I want to write some code that will check to see if a
bookmark exists and if it does, run a userform. Once the
user has filled in the userform and clicked OK, I want the
code to find the bookmark and delete it.
If the bookmark doesn't exist, then I don't want the code
to run...

I have the following code:
Sub Autonew()
If ActiveDocument.Bookmarks.Exists("new") = True Then
FrmOutwardLetter.Show
End If
End Sub

and within the userform code I have the following code to
delete the bookmark:
ActiveDocument.Bookmarks("new").Select
Selection.Delete

BUT nothing seems to be working! The userform doesn't
show anymore - What am I doing wrong? (It's probably all
wrong!).

I was trying to create a custom boolean property, set its
value to false and change it to true once the userform
runs. Then always check for the value of the said
property when document is opened, and if it is true, do
not run the code. Wasn't sure how to do this as this is
all new to me... :o(

Thanks in advance
Lee

Re: Check for Bookmark then run userform by Jezebel

Jezebel
Wed Aug 25 23:07:51 CDT 2004

The first part of your code should certainly work to show the form if the
bookmark exists. If your form is not displaying, put a stop statement into
your code and check at that point: does the bookmark actually exist?

However, a bookmark is a poor choice for this. A DocProperty or DocVariable
would be a better choice.

The code that deletes the bookmark will work, but I'm not sure that it does
what you want: for purposes of your code you want to delete the bookmark
itself. What you have deletes the range of your document to which the
bookmark applies. Simpler is



"Lee" <anonymous@discussions.microsoft.com> wrote in message
news:050001c48b18$d5c83400$a301280a@phx.gbl...
> I want to write some code that will check to see if a
> bookmark exists and if it does, run a userform. Once the
> user has filled in the userform and clicked OK, I want the
> code to find the bookmark and delete it.
> If the bookmark doesn't exist, then I don't want the code
> to run...
>
> I have the following code:
> Sub Autonew()
> If ActiveDocument.Bookmarks.Exists("new") = True Then
> FrmOutwardLetter.Show
> End If
> End Sub
>
> and within the userform code I have the following code to
> delete the bookmark:
> ActiveDocument.Bookmarks("new").Select
> Selection.Delete
>
> BUT nothing seems to be working! The userform doesn't
> show anymore - What am I doing wrong? (It's probably all
> wrong!).
>
> I was trying to create a custom boolean property, set its
> value to false and change it to true once the userform
> runs. Then always check for the value of the said
> property when document is opened, and if it is true, do
> not run the code. Wasn't sure how to do this as this is
> all new to me... :o(
>
> Thanks in advance
> Lee
>



Re: Check for Bookmark then run userform by Lee

Lee
Sun Aug 29 17:16:00 CDT 2004

I have tried a docvariable but can't seem to get it to
work...
I tried:
If ActiveDocument.Variables("new").Value = 0 Then
FrmOutwardLetter.Show
End If
and I had a variable in the document named "new".

This is probably wrong... Don't know how to do this as I'm
new at VBA. Can anyone help with some code please?

Thanks

>-----Original Message-----
>The first part of your code should certainly work to show
the form if the
>bookmark exists. If your form is not displaying, put a
stop statement into
>your code and check at that point: does the bookmark
actually exist?
>
>However, a bookmark is a poor choice for this. A
DocProperty or DocVariable
>would be a better choice.
>
>The code that deletes the bookmark will work, but I'm not
sure that it does
>what you want: for purposes of your code you want to
delete the bookmark
>itself. What you have deletes the range of your document
to which the
>bookmark applies. Simpler is
>
>
>
>"Lee" <anonymous@discussions.microsoft.com> wrote in
message
>news:050001c48b18$d5c83400$a301280a@phx.gbl...
>> I want to write some code that will check to see if a
>> bookmark exists and if it does, run a userform. Once
the
>> user has filled in the userform and clicked OK, I want
the
>> code to find the bookmark and delete it.
>> If the bookmark doesn't exist, then I don't want the
code
>> to run...
>>
>> I have the following code:
>> Sub Autonew()
>> If ActiveDocument.Bookmarks.Exists("new") = True
Then
>> FrmOutwardLetter.Show
>> End If
>> End Sub
>>
>> and within the userform code I have the following code
to
>> delete the bookmark:
>> ActiveDocument.Bookmarks("new").Select
>> Selection.Delete
>>
>> BUT nothing seems to be working! The userform doesn't
>> show anymore - What am I doing wrong? (It's probably
all
>> wrong!).
>>
>> I was trying to create a custom boolean property, set
its
>> value to false and change it to true once the userform
>> runs. Then always check for the value of the said
>> property when document is opened, and if it is true, do
>> not run the code. Wasn't sure how to do this as this is
>> all new to me... :o(
>>
>> Thanks in advance
>> Lee
>>
>
>
>.
>