Automate keystrokes w/ VBA?

  • Thread starter Thread starter Rich Roller
  • Start date Start date
R

Rich Roller

Goal: Allow user to jump to a certain screen/field in Outlook 2003 to
quickly tag a contact record. Essentially I want to automate the following
sequence of keystrokes:
->Contacts
->All Fields tab
->All Contact Fields
->User Field 4 & enter a value of "HH"

I had imagined I'd just go into Macro and say "start recording keystrokes"
but that doesn't seem to exist. Correct?

Then I thought I could write something in VBA but I'm a VBA novice and I
don't quite know how to do what I want. Does anyone know/have any code that
would do this?

And if it can be done w/ VBA, can I trigger it from a hotkey combination or
a custom toolbar button?

Or if there's another/better way (other than VBA) of accomplishing what I
want, I'm all ears.

Thanks in advance for an advice!

-Rich
 
Goal: Allow user to jump to a certain screen/field in Outlook 2003 to
quickly tag a contact record. Essentially I want to automate the following
sequence of keystrokes:
->Contacts
->All Fields tab
->All Contact Fields
->User Field 4 & enter a value of "HH"

I had imagined I'd just go into Macro and say "start recording keystrokes"
but that doesn't seem to exist. Correct?
Correct.

Then I thought I could write something in VBA but I'm a VBA novice and I
don't quite know how to do what I want. Does anyone know/have any code that
would do this?

ActiveInspector.CurrentItem.User4 = "HH"
And if it can be done w/ VBA, can I trigger it from a hotkey combination or
a custom toolbar button?
[snip]

Custom Toolbar Button is trivial: (View/Toolbar/Customize...). To add a
keyboard shortcut, see <http://support.microsoft.com/?kbid=252427>.
 
AWESOME! Thank you Michael. I never thought it would be such a simple,
one-line procedure! -Rich

Michael Bednarek said:
Goal: Allow user to jump to a certain screen/field in Outlook 2003 to
quickly tag a contact record. Essentially I want to automate the
following
sequence of keystrokes:
->Contacts
->All Fields tab
->All Contact Fields
->User Field 4 & enter a value of "HH"

I had imagined I'd just go into Macro and say "start recording keystrokes"
but that doesn't seem to exist. Correct?
Correct.

Then I thought I could write something in VBA but I'm a VBA novice and I
don't quite know how to do what I want. Does anyone know/have any code
that
would do this?

ActiveInspector.CurrentItem.User4 = "HH"
And if it can be done w/ VBA, can I trigger it from a hotkey combination
or
a custom toolbar button?
[snip]

Custom Toolbar Button is trivial: (View/Toolbar/Customize...). To add a
keyboard shortcut, see <http://support.microsoft.com/?kbid=252427>.
 
Yes custom toolbar buttons are easy... but do you know how to get the button
to display ONLY in the standard Contacts form but not in other
screens/forms? (After I added the button in Contacts, it's also showing up
in message views/forms)

Thanks again.

-Rich
 
Yes custom toolbar buttons are easy... but do you know how to get the button
to display ONLY in the standard Contacts form but not in other
screens/forms? (After I added the button in Contacts, it's also showing up
in message views/forms)

I don't know. I suspect you would have to create and publish a form for
your contacts. There's another newsgroup which seems to deal with that:
microsoft.public.outlook.program_forms
 
I'll try to find the answer for that.

Thanks again for the simple but crucial VBA syntax you gave me!

-Rich
 
Can't you just test for Inspector.CurrentItem = olContact when you create
your button? Don't create the button if the test is True.
 
Can't you just test for Inspector.CurrentItem = olContact when you create

(Shouldn't that be: Inspector.CurrentItem.Class = olContact ?)
your button? Don't create the button if the test is True.

That assumes the OP creates the button programmatically via an event
handler; I doubt that.
 
Yes, sorry, Inspector.CurrentItem.Class = olContact.

The button should be created in an event handler for NewInspector, that's
the best way to do it.
 
Guys I'm not sure I totally follow.

I know how to create a button via the add/remove GUI (customize toolbar) but
how do I create a button conditionally? "in an event handler"? Or is it
possible to edit the properties of the button once it's created to make it
display conditionally (only if in Contacts form/view)?

Again, I'm novice programming so it'd have to be pretty easy, as was the
above tip for jumping to a specific field.

-Rich
 
If you handle the NewInspector event of the Inspectors collection and you
are only interested in creating your button for contacts the first step is
to check for contacts when that event fires. That's the code that uses
Inspector.CurrentItem.Class = olContact. If it's anything but a contact you
don't instantiate the Inspector wrapper.

Code for creating buttons in Inspectors using a wrapper and collection and
creating the actual buttons in the class is available for both VB 6 and C#.
The C# example is at http://www.outlookcode.com/codedetail.aspx?id=797 and
the VB 6 code is at
http://www.slovaktech.com/code_samples.htm#InspectorWrapper. That should get
you started.
 
Back
Top