We help IT Professionals succeed at work.

VBScript needed for Outlook manipulation

937 Views
Last Modified: 2012-05-08
I need to create a VBScript which will initially create a new Outlook toolbar (Outlook 2003 & Outlook 2007) populated with a list of menu items that link to Outlook templates, I then need a script which will add/remove/amend templates as neccessary.  These scripts will need to be run on all client PCs in the business.

I'll admit I know nothing about VBScript but can code in VBA (which I gather is similar).

My biggest issues are knowing the right code (or finding the right resource) to allow me to create these scripts, and then knowing the best method for running these scripts on all client PCs when we need to.
Comment
Watch Question

CERTIFIED EXPERT

Commented:

Author

Commented:
That doesn't actually answer anything, its just a link to someone else's unanswered question on another site that contains code that the requester himself admits doesn't work properly.
CERTIFIED EXPERT
Top Expert 2010

Commented:
Hi, SquareOneResources.

Creating a toolbar and adding items to it is simple.  There's more to making this solution work.  You also need code to handle the button click events.  Deploying the solution is another issue you need to consider.  While you could add the toolbar using VBScript the event handling code has to run from inside Outlook.  That means adding Outlook macro code to every computer or writing an Outlook add-in.  An add-in is your best bet since there are no automated means of distributing Outlook macro code.  I can provide sample code that creates a toolbar and adds items to it.  If you want to go the add-in route I can point you to a template that'll make the job easier.

Author

Commented:
The add-in solution sounds better, I was under the impression the macro code would run and then be done.

If you could point me in the right direction to create an add-in that would be great, though I will be needing a drop down menu on a toolbar rather than a set of buttons.
CERTIFIED EXPERT
Top Expert 2010

Commented:
"I was under the impression the macro code would run and then be done."
That's correct for adding the toolbar and pull down menu.  Depending on how you approach this that might be true for handling the user making a selection from the menu.  There are two approaches.  The first of these is to use the OnAction parameter of the pulldown menu.  Something like

    Dim objPulldown As Office.CommandBarComboBox
    Set objPulldown = objBar.Controls.Add(msoControlComboBox)
    objPulldown.OnAction = "Name of the procedure to run when the user makes a selection"

The procedure you specify has to be code that's in Outlook and you have to explicitly specify the full path to the procedure.  The second approach is to define the object using the WithEvents options.  Something like

    Dim WithEvents objPulldown As Office.CommandBarComboBox
    Set objPulldown = objBar.Controls.Add(msoControlComboBox)

The code can then trap the Click event objPulldown generates when the user makes a selection.  Both approaches accomplish the same thing, but I believe the latter provides more flexibility.  Both approaches must be implemented inside of Outlook using VBA.  Because there is no automated means of distributing or updating changes to Outlook macros code that must run from inside of Outlook is a poor choice for a wide audience.  In other words, the more people that need this the more you need to use an add-in.  Add-ins are COM components that run outside of Outlook.  COM components can be installed and updated using readily available tools.  That's why companies that develop solutions for Outlook universally use add-ins.  

"If you could point me in the right direction to create an add-in that would be great"
Here is a link to a template.  This is for VB6.
http://www.microeye.com/resources/template.htm

Author

Commented:
Ahh...think we might have slightly crossed wires, I don't want the macro to handle what happens when the user selects an option, Outlook should take care of that.  I just want the macro to add the toolbar in the first instance and then one to maintain it as we add/remove templates.

Here is a link to the manual process that we are trying to automate:
http://articles.techrepublic.com.com/5100-10878_11-5178650.html

Author

Commented:
The macro/VBscript for maintaining the toolbar and its contents will be rolled out as and when needed, we will not have this sitting on each machine constantly.
CERTIFIED EXPERT
Top Expert 2010

Commented:
"I don't want the macro to handle what happens when the user selects an option, Outlook should take care of that"

It won't.  Outlook has no means of handling a custom toolbar.  How would it know what it is that you want a button to do?

Author

Commented:
"Outlook has no means of handling a custom toolbar"
I've had the custom toolbar running on my PC now for a week or so.

In the attached guide you can create a custom toolbar which contains a drop down menu, the menu items hyperlink to the associated template location.  Since VBA and VBScript allows you to manipulate the application at the application level there will be a way to automate it, but since Outlook doesn't have a record macro function I cannot record certain steps to get started with the required object code.

CERTIFIED EXPERT
Top Expert 2010

Commented:
Sorry, but I don't follow what you're saying.  Are you're saying that you have a toolbar with a drop down menu and Outlook automatically does something when you make a selection?  If so, then I'd like to see how you accomplished that.  

Author

Commented:
BlueDevilFan?
CERTIFIED EXPERT
Top Expert 2010
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Excellent, thanks I'll give it a whirl and will let you know how I get on.

Author

Commented:
I get this error when accessing the link from a toolbar created with the script.  I've tried changing the location of the template to the location set in Office but it makes no difference.


test.gif
CERTIFIED EXPERT
Top Expert 2010

Commented:
In testing I found that paths with spaces often caused problems.  As a test try a path that doesn't have any spaces.

Author

Commented:
Works like a charm!  Thanks!
CERTIFIED EXPERT
Top Expert 2010

Commented:
You're welcome.  Glad I could help.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.