VBA open document

I'm not sure if this is the right place for this question so if there is a better place to post it, pleast tell me.  I have a COM addin for MS Word.  Whenever the user presses a button on a toolbar I created in Word, I want to call a method, UpdateDocument, on the COM addin and pass it the full text of the current document.  This is what my application does:

1) When a new Word document is created, I get a DocumentChange event and in it, I call the Init method of my addin.  This returns an id number.

2) When the user clicks the toolbar button, I call the UpdateDocument method and pass it the id number of the ActiveDocument as well as the full text of the Active Document (I've been using ActiveDocument.Range.Text.  Is this right?).

My question:  Is there any way for me to associate an open document with an id number?  I could do it with a global hashtable where ids were indexed by filenames of documents, but VBA doesn't have a hashtable structure.  Maybe it's possible to set variables or store data in documents themselves and access these variables/data via ActiveDocuement?  Is there any way to do this?

P.S. I am running VBA code from a template if that's important.  Thank you very much for your help.  If you need my VBA code, just ask.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You could use the CustomDocumentProperties object to store custom info with the document:

Dim cdp As DocumentProperties

'Add a document property
Set cdp = ActiveDocument.CustomDocumentProperties
cdp.Add "ID", False, msoPropertyTypeNumber, 1234

'Read the Document property
n = ActiveDocument.CustomDocumentProperties("ID").Value

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
You could use the Dictinary object from the Microsoft scripting library to provide hashtable functionality (add a reference to 'Microsoft Scripting Runtime' - scrrun.dll). It provides basic hashtable functionality and is very easy to use. This should be possible with VBA too.

Dim dic as new Dictionary

' Store
set dic.Item(id) = WordDocument

Dim doc as WhateverAWordDocumentIs

' Check if Id is valid
If dic.Exists(id) then
    set doc = dic.Item(id)
End If

' Do something with doc

Best regards,

You can create and store an indefinite number of variables in a Word document

Doc.Variables.Add "MyVariable", "MyValue"
Storedvalue = Doc.Variables("MyVariable")
thedude112286Author Commented:
Excellent job.  I can't thank you enough for your very quick and extremely helpful response!  Keep up the good work!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.