Open specific word document and run VBA code to display user form

G

GrantS

This appears to be a problem a lot of folk have had over several
years. I have tried several tips found on Google. No Joy so far!

I want users to double click on a particular Word (>Word 2000)file and
when this opens, to display a userform with several listboxes. Once
the list selections have been made, users will hit a "fetch" command
button to populate the document. I want the document to be invisble
until the user has made their selections and hit "Fetch" (Easy to to
this in Excel via placing code in Workbook_open Event).

Word examples I have found relate to using and AutoExec in Normal.Dot
and this works OK. The problem is that this code will then fire when
any document is loaded. I cannot allow this in my case. Other options
I have tried and have failed are using and Add-in Templates. I tried
placing an Add-in template in the same folder as Winword.exe and also
in the default templates folder pointed to in the "File Locations" in
Options. The Add_in that I select via Tools-Templates & AddIns" runs
the code whenever I select/Attach it BUT this selection does not
persist when the document is saved - closed - then re-opened. I tried
playing with the code creating a "ThisApplication class" and a module
in the Add-in (Template to attach to my document) as per the below
site:

http://www.mvps.org/word/FAQs/MacrosVBA/PseudoAutoMacros.htm
http://www.mvps.org/word/FAQs/MacrosVBA/AppClassEvents.htm

Also tried this below snippet found on Google:

"An autoexec macro runs only when Word is started. Where is your
autoexec
macro stored? Is it inside an addin that is loaded from Word's startup
folder or maybe in Normal.dot?
If it's in another template that not is loaded automatically your code
wouldn't run.
If you want to run your code at all times when Word is started store
your
template in the folder where Tools - Options - FileLocations- Startup
points
to.
If you want it to run whenever a document based on a template is made
or
opened name your macro AutoNew or AutoOpen and store it in the
template."

No Joy here.

If anyone has any code example that fires VBA code for a specific Word
file when its is opened OR can point me to another explanation that
might help me, I would be chuffed.

Thanks in advance

Grant
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Grant,

The particular Word file that you are talking about should be a template
containing an autonew macro that calls the userform.

See the article “How to create a Userform” at:

http://www.mvps.org/word/FAQs/Userforms/CreateAUserForm.htm

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 

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