VB Automation of a Word 2002 Template

D

DiscGolfer

I got this Word Basic programming assignment to parse a drop down combo box
on a template file. The combo box has an account description (####). The
goal is to copy the 4 characters of the account number into a separate field
on the form. The form is an export of a loan request from one of our
mainframe systems. When ever the template is opened a mail merge process
happens and it gets auto-saved as a word document.

I think it is a limitation of Word Basic to have VBA code in a document
template. I can see all over where it talks about creating MACRO's and such,
but not straight VBA code. I specifically need to call the combo box change
event to parse the account number and copy it to another field on the
document template. But I am having difficulties calling that change event.
Is this something that can be done with VBA code in a document template. Any
examples of VBA code in a document template will be much appreciated.
Best,
 
J

Jean-Guy Marcil

DiscGolfer was telling us:
DiscGolfer nous racontait que :
I got this Word Basic programming assignment to parse a drop down
combo box on a template file. The combo box has an account
description (####). The goal is to copy the 4 characters of the
account number into a separate field on the form. The form is an
export of a loan request from one of our mainframe systems. When
ever the template is opened a mail merge process happens and it gets
auto-saved as a word document.

I think it is a limitation of Word Basic to have VBA code in a
document template. I can see all over where it talks about creating
MACRO's and such, but not straight VBA code. I specifically need to

???
Macro *are* VBA code.
What do you mean?
call the combo box change event to parse the account number and copy
it to another field on the document template. But I am having
difficulties calling that change event. Is this something that can be
done with VBA code in a document template. Any examples of VBA code
in a document template will be much appreciated.
Best,

Why not just use a REF field?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jezebel

I think you must have been skipping classes in this course of yours, or you
didn't do any of the reading.

1. WordBasic and VBA are not the same thing. WordBasic is the programming
and macro language provided with Word before VBA was invented. It became
obsolete more than ten years ago. It's still supported -- after a fashion --
for backward compatability, but your assignment seems to be to write in VBA,
not WordBasic. Your statement "a limitation of Word Basic to have VBA code"
is simply meaningless.

2. Macros *are* VBA.

3. All VBA code has to go somewhere (obviously). Your choices are: a) the
document, b) a template, or c) an add-in. Your call.

4. You don't call events. By definition, events happen by themselves: event
code is called automatically.

5. Your combobox: do you mean a dropdown in the document, or a combobox on a
userform? Either way, it's not in the template, but in the document created
FROM the template. If the former, you write an OnExit macro; if the latter,
the click or change events depending on how your userform works.
 
D

DiscGolfer

Thank-you for your post.

Yes, I think I did skip the WordBasic class. I am trying to use "Office
VBA" to do the programming. By combobox I mean that right now there is a
dropdown in the document. I couldn't find the ChangeEvent when I looked in
the VBA code window. So I tried adding a combobox on a userform. This whole
document template is called by a "TreeView WordBasic" application. It is a
Word document with a treeview control that allows the user to pick the
correct document template related to which loan application form needs to be
processed.

I will recommend to our IT department that this whole process gets updated
to VB 6.0.

When I think of a "MACRO", I get a picture in my mind of the kind of macros
in Access. I compare that to VBA code which is straight code. But come to
think of it, when i compare a "MACRO" in Excel, it creates the straight VBA
code. Sorry for the confusion of language here.

Thank-you.
 
D

DiscGolfer

REF Field? How do I do that? I am recommending to my IT department to have
this upgraded from the old WordBasic to a more suportable VB 6.0 project.

When I think of a "MACRO", I get a picture in my mind of the kind of macros
in Access. I compare that to VBA code which is straight code. But come to
think of it, when I compare a "MACRO" in Excel, it creates the straight VBA
code. Sorry for the confusion of language here.

Thanks for your input, I appreciate it.
 
J

Jezebel

If you have a dropdown in the document, put your document into design mode,
right-click the dropdown, select properties, set the name of the macro you
want to call.

"Treeview WordBasic application" means nothing. A TreeView is a control you
can put on a UserForm; but not using WordBasic.

VB6 would be absurd overkill for so simple a requirement; and also unwise
given that the days of VB6 are numbered.
 
J

Jean-Guy Marcil

DiscGolfer was telling us:
DiscGolfer nous racontait que :
REF Field? How do I do that? I am recommending to my IT department

Your dropdown will have a bookmark name (Double click it to access the
properties and note the bookmark name in the lower right corner of the
properties dialog). Let's say that this name is "Dropdown1".

Then, wherever you want the content of the dropdown repeated in the document
do this:

Place the insertion point
CTRL-F9;
This will insert a pair of {} (Note that these braces may not be typed
directly, you must use "CTRL-F9" or "Insert > Fields...");
Between the {} type REF Dropdown1;
You will now have {REF Dropdown1};
With the cursor between the {} do F9 to update the field value;
You can select the whole field and do copy/paste to use it elsewhere.

In your Dropdown properties make sure you click "Calculate on exit" so that
the REF fields will be updated automatically.


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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