VBScript - To launch a button, which when clicked runs a macro that opens a custom form

A

Anurag Batra

Hello,

This was working in Outlook 2002. Using vbscript we created a button
that opened an oft file when clicked. We did this because it was
deployed to a number of employees. They have a button on their toolbar
which when they clicked launched the form. However now we are moving
to Outlook 2007 and now we face a bunch of problems. It does not work
at all. So this is what I have done till now.

First the custom form was published and deployed to the Organization
group. After that I created a macro that would launch the form. It
works but everytime I logon to the test machine and try to run the
macro it gives a security message alert. How can we avoid that? Once I
click ok it works fine from there. Below is the code for the macro.
--------------------------

Sub MyHandler()
Set myFolder = Session.GetDefaultFolder(olFolderCalendar)
Set myItem = myFolder.Items.Add("IPM.Note.CPSCallReports")
myItem.Display
Set objTasks = Nothing
Set objTask = Nothing
'MsgBox ("button clicked...yipee!!")
End Sub
-------------------------
The macro works fine when you launch it manually.

Now I have vbscript code that creates the toolbar button which when
clicked tries to launch the macro. The script when run creates the
toolbar button. But nothing happens when you click on the button.

-----------------------------------
Dim oActExp
Dim cmdbar
Dim cmdbtn
Set olApp = CreateObject("Outlook.Application")
set oActExp = olApp.ActiveExplorer
Set cmdbar = oActExp.CommandBars.Add("Open Custom Forms Bar", 1)
set cmdbtn = oActExp.CommandBars("Open Form").Controls.Add(1)
With cmdbtn
.Caption = "Call Report"
.OnAction="MyHandler"
End With
cmdbar.Visible = True
cmdbtn.Visible = True
msgbox("Setup complete!")
-----------------------------------

I have tried various options of OnAction event but nothing happens. I
even tried to do this
..OnAction = MsgBox("foo")
but nothing happened as well.

My final goal is to have a vbscript which I can ask users to run on
their machine which would create the button and the macro. The form is
already deployed.

regards,
Anurag
 
J

Jeff Hopper

You could select Tools | Macro | Security | No security check for macros
(Not recommended) on every machine to get rid of the security alert. Note
that the selection is not recommended by MS, but they do provide the option,
so use your best judgement for your situation... You may need to restart
Outlook for that setting to take effect.
 
J

Jeff Hopper

I have seen that behavior when you don't restart Outlook after making the
security change. Are you sure you're re-starting it and the OUTLOOK.EXE
process is ending before attempting to launch Outlook and use the button?
 

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