Deploy code to launch a custom form from Toolbar button.

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
 
K

Ken Slovak - [MVP - Outlook]

I'm totally confused.

Where is this VBScript code running? If it's in the Outlook form never use
New or CreateObject to create an Outlook Application object. You must use
the intrinsic Application and Item objects to be considered trusted. All of
your Outlook objects must then derive from those intrinsic objects.
Otherwise your code is not trusted and will fire the security prompts.

Now why are you using macros? I assume you mean Outlook VBA code? That's not
a best practice for deployment and calling an Outlook macro from form code
may work but is not supported.

Using an OnAction like that may also cause the form to become one-offed,
which also will make it untrusted and it won't run form code.

The best practice would be to create a COM addin to create the button and
handle it's Click event.
 

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