Property autofill contents

S

SteveDB1

Good morning all.
I've been working with Excel for a while and have become reasonably
comfortable with macros.
Last week, a colleague and I were discussing having an autofill macro that
he'd made for excel which populates the contents, author name, and keywords,
etc... boxes in the property dialogue box.
He'd asked me if I'd seen anything like that for Word. (it's important for
the work we do here)
I've looked around using a few different keywords here, and cannot locate
any discussions on this topic for Word.
Are there any discussions available where this topic has been discussed? If
so, where might I find them?
Thank you for your responses.
Best.
 
J

Jay Freedman

SteveDB1 said:
Good morning all.
I've been working with Excel for a while and have become reasonably
comfortable with macros.
Last week, a colleague and I were discussing having an autofill macro
that he'd made for excel which populates the contents, author name,
and keywords, etc... boxes in the property dialogue box.
He'd asked me if I'd seen anything like that for Word. (it's
important for the work we do here)
I've looked around using a few different keywords here, and cannot
locate any discussions on this topic for Word.
Are there any discussions available where this topic has been
discussed? If so, where might I find them?
Thank you for your responses.
Best.

Office documents have two kinds of properties that are stored in separate
collections: BuiltInDocumentProperties and CustomDocumentProperties.

You can use Google and Google Groups searches for these two terms to find
plenty of discussions on the topic -- for example,

<http://groups.google.com/groups?as_q=builtindocumentproperties&as_ugroup=microsoft.public.word.*>

If you have specific questions about working with these collections, come
back here any time!

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
S

SteveDB1

Jay,
Thank you for your response.
The information is indeed helpful.
I checked out the google groups, and found a couple of interesting articles,
MS KB articles on the DSOfile.dll file, etc....
I then called those two up in the Office help file.
Two items initially come to mind after having read the articles provided in
the help file.
It seems to me that the BuiltInDocumentProperties allows for reading the
properties, and CustomDocumentProperties allows for editing those
properties,m or creating new ones not normally accessible, or allowed.
Is this correct?
where can I find a digitally accessible library that gives all the property
items I can modify, or look for?
The help file appears to be limited, and we don't have a VBA book for Word.
Again thank you for the course direction.
 
J

Jay Freedman

Hi Steve,

The help topic on the BuiltInDocumentProperties suggests that you use the Object
Browser to see what properties are available. To do that, in the VBA editor,
press F2 to open the browser; type wdBuiltInProperty in the search box and click
the binoculars button next to it. The bottom right pane of the browser will
display all the valid values.

Also, the Example section of the help topic contains a macro called
ListProperties. (Sadly, the 2007 version of the help topic omits the Sub
ListProperties() line at the top and the End Sub line at the bottom, which are
necessary.) If you copy/paste that macro into a module in the VBA editor and run
it, it will create a list of all the built-in properties defined in the current
document.

Some built-in properties are editable (read/write) and others are read-only. The
best way to know which ones are editable is to look at the File > Properties
dialog; any that have an editable text box are read/write, such as

ActiveDocument.BuiltInDocumentProperties(wdPropertyComments).Value = "Wow"

but any others (such as wdPropertyPages) are read-only.

The CustomDocumentProperties collection is empty until you define one or more
values, either in code or through the Custom tab of the File > Properties
dialog. You can name them anything you like, and any you define are always
editable.
 
S

SteveDB1

Thanks again.
This is definitely helpful.
I did find the macro example, and tried it. For some reason my help file
shows the sub ListProperties()
and
End Sub
lines.
My next question is:
What would be involved in pulling strings of text from a letter to insert
into the editable property text box?
The author is preset, but inserting the title, keywords, etc...
With excel it's fairly straightforward because the data is typically within
a single cell, or range of cells we can readily determine, and are reasonably
consistent.
I thought further about this last night, and realized that while I could
call a line, and column #, they're not the same all the time.
And on some letters we have tables we insert with the data we're serving our
clients with. Which would then call a completely different set of columns,
and line #'s.

Would I have it look for specific text strings, and if it matches, choose a
range of columns, and maybe even two lines of the text?
My initial thoughts were to have a dialogue box come up to ask for the info
to be placed in the property dialogue box, but we're attempting to bypass the
human input requirement, and just have it access the final data
automatically, as we have in excel.
Thanks again for your help. I really appreciate it.
Best.
 
J

Jay Freedman

There are many schemes for marking documents to enable macros to extract
data from them. Which one might work best for you depends very much on your
workflow and what external programs interact with your documents.

How are your documents being created? Are you starting with a template, or a
mail merge, or something else?

It might be possible to use DSOFile.dll to put data directly into document
properties, and use DocProperty fields to display the values in the body of
the document.

If that doesn't work out, you could use form fields, bookmarks, custom
styles, or any of several other means to mark the boundaries of the text.

It would also be useful to know what versions of Word need to be
accommodated.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
S

SteveDB1

Jay,
We're starting with templates. They have been standardized, so pulling
common themes seems doable to me. We might need to vary with certain details,
but I have been looking at our templates to consider this further.
External program interaction... Of that I'm not certain at present. So far,
I think it'd be only one or two programs- if at all- and those I wouldn't
know just yet. I'll be speaking with my colleague to get the skinny on that
one, and he's not here right now.
I did boomark the DSOfile .dll article, so I'll go back and look more
closely at that one. Since we have fairly strict IT rules here, I'll
definitely need approval for that one.
As for version-- our entire office is using Office 2007, Pro. Around 70 or
so seats.

We've actually discussed the bookmark, form fields option already. My
colleague thinks that'd be far grander, and more detailed a project than he
wants to get going. It'd be one thing if we had someone to task with
populating the bookmarks, and setting up the form fields, but there are only
two of us even talking about this right now (we'd be the one's doing the prep
work), and I'm the one researching, asking questions, etc..., in between my
own work load.
And while I do think that this might be the easiest, we have such a large
clientele that it'd take a while to populate the bookmarks to use in the form
fields.

Again, thank you for your help.
Best.
 
J

Jay Freedman

Hi Steve,

Because you all have Office 2007, you have a method available to you that's
new in that version: You can set up the templates with "content controls"
instead of form fields or bookmarks. The content controls can be bound to
the document properties (that means the content controls display whatever is
in the document properties and vice versa). In the Office 2007 file format,
the document properties are stored as text in an XML file.

Then you can use very simple code (or even Notepad) to insert values into
the XML file, and the results will appear in the document.

The article at http://msdn2.microsoft.com/en-us/library/bb264572.aspx gives
an elementary demonstration of this technique. There's a lot more you can
do, but that will give you a start. For more, use a Google search for Office
OpenXML.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
S

SteveDB1

Jay,
OpenXML, is that the same as we make the custom ribbon menus with in Excel?
I know we use the CustomUI Editor to create XML menus. It's been really
helpful for customizing the pulldown menus we use now with 2007.
I'll review the link you sent, and look it up on google.
Content controls.....
Thanks again.
 
J

Jay Freedman

No, not quite the same thing. They're both "flavors" of XML, but the one you
saw is RibbonX which is specialized to describe the Ribbon. OpenXML is for
describing documents.
 

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