How can I populate a list box with all open word docs in VBA

M

mr tom

Hi,

Using VBA:
How would I populate a list box with the filenames of all open word docs?
User then selects the file they want.
How could I ensure future macros operate on that file?

For completeness, I'd like this to check all open incidences of Word, but if
that's really hardcore, then I'll stick with what won't go straight over my
head as I've still a lot to learn and need to ensure I can mantain what I
build.

Many thanks.
 
D

Doug Robbins

Word has such a list built into the Windows menu. Why reinvent the wheel?
Having you macros run on the ActiveDocument will cause them to run on the
document that the user selects from that list.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

mr tom

Am building quite a complex system - won't go into the business side and
reasons as they're probably not too interesting, but basically, I'm trying to
build something that will take data from 2 standard docs (no problem there)
and 2 forms (filename will always be different, but based on the customer
info) and put it into one advice pack, specific to each customer.
Idea is, as this will be operated by people without much IT savvy, they
would simply have to:
Open the 2 forms, and the control file.
Click the button on the control file.
Specify which of the forms is which from dropdown lists.
Sit back and wait for the reults.

Plan is:
The control file would open a template, throw up the dialog to get them to
select the forms, insert the relevant bits of each form (I produced the form
templates and the relevant formfields are named, so I can call them); then it
would open the 2 standard docs, insert the bits from those, and finally dump
the whole thing to a pdf.
Second revision will also include a implementation plan bespoke to each
customer built through a MS Project template, and also dumped to pdf.

I think the list box is the most foolproof way.
I've also ensured that none of the forms contain any code as they're going
to have to travel through firewalls etc - hence the control file.

Many thanks,

Tom.
 
J

Jonathan West

Hi mr tom

The Documents collection contains all the open documents. Something like
this would do the needful for filling the listbox

Dim oDoc as Document
For each oDoc in Documents
ListBox1.AddItem oDoc.Name
Next oDoc


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
M

mr tom

That's absolutely fantastic. It works brilliantly.

That's the third time you've provided a simple, efficient and accurate
answer to one of my queries.

Many thanks,

Tom.
 

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