PDA

View Full Version : Solved: Assign Variables On Open



Levski
04-03-2005, 08:03 AM
I am opening a document through a com interface that adds a bookmark containing a delimited string, i.e sarah|girl|texas (where | is the delimiter)

What I would like to do on open is to separate the elements and store them as public variables so they can be used by other macros, i.e

Sub Name()
Selection.TypeText Text:=Name
End Sub

would produce Sarah when Name() is called.

It is the document_open macro that I cant get to work -

Sub Document_Open()
Name = Split(Bookmarks("BookMarkName").Range.Text, "|")(0)
Gender = Split(Bookmarks("BookMarkName").Range.Text, "|")(1)
' etc
End Sub

Should assign values to Public Name As String (etc)

But this does not work. When Name() is called nothing happens. No error msg either.

The document_open should conclude with the deletion of the bookmark, but I have yet to get that far.

Can anybody help? If I have gone about a completely inefficient way I would be happy to change tact entirely.

Thank you in advance.

mdmackillop
04-03-2005, 08:08 AM
Hi Levski,
Welcome to VBAX

I'm guessing that Document_Open may be running before the Bookmark is created. Can you test for that with a message box?

Levski
04-03-2005, 08:26 AM
Thank you for the prompt reply.

The msgbox opens first, suggesting I am trying to dissect a string that does not exist at that point.

Any ideas how I can ensure that the macro runs automatically after the bookmark has been created? I do not know much about Word at all Im afraid, just creating a word link for an app in done in delphi.

Levski
04-03-2005, 10:26 AM
Managed to get the variables straight through the interface without having to use the bookmark.

Thanks all the same. I will probably be back : pray2:

Anne Troy
04-03-2005, 05:09 PM
Levski: Sounds like it's solved. If so, could you click the Thread Tools dropdown (top of page) and choose Mark Solved?

Thanks! And welcome to VBAX.