troubleshooting Question

VBScript to add an .oft Form file into a new Outlook Toolbar

Avatar of Rafael Adamska
Rafael AdamskaFlag for Brazil asked on
Visual Basic ClassicOutlookVB ScriptVBA
6 Comments1 Solution265 ViewsLast Modified:
Hi everyone.

     I'm trying to develop a code in VBScript (.vbs file) that adds a button on Outlook (2010) and runs a custom form (already developed, .oft file) that is on teh same directory as the .vbs file.

     I have to install this button and custom form to more than one computer, so the ideia is that the VBScript install the .oft file permanently, so the user could access that form by pressing the new button without have to execute the .vbs file or install the form again.

    I'm halfway there, I was looking to this other topic, but I couldn't install the .oft Form with that. Could someone please point me the right direction to finish this VBScript?

Topic: https://www.experts-exchange.com/questions/25051822/VBScript-needed-for-Outlook-manipulation.html#a26403266

What I've got so far:

Const msoControlButton = 1
Const msoCommandBarButtonHyperlinkOpen = 1

'Change the toolbar name on the next line as desired.'
Const CMDBAR_TITLE = "Service Desk Bar"


Dim objItem     ' As Outlook.ContactItem
Dim objFD       ' As Outlook.FormDescription
Dim fso         ' As FileSystemObject    
Dim olkApp, olkSes, ofcBar, ofcButton
Set olkApp = CreateObject("Outlook.Application") ' As Outlook.Application
Set olkSes = olkApp.GetNamespace("MAPI")

'Change the profile name on the next line as needed.'
olkSes.Logon "Outlook"

'Add custom Form
Set fso = CreateObject("Scripting.FileSystemObject")
CurrentDirectory = fso.BuildPath(fso.GetAbsolutePathName("."), "Teste1.oft")
Set objItem = olkApp.CreateItemFromTemplate(CurrentDirectory)
Set objFD = objItem.FormDescription

With objFD
    .DisplayName = "TemplateServiceDesk"
    .PublishForm olPersonalRegistry
End With
objItem.Close olDiscard

On Error Resume Next
'Clear any bars
Set ofcBar = olkApp.ActiveExplorer.CommandBars.Item(CMDBAR_TITLE)
If TypeName(ofcBar) <> "Nothing" Then
    ofcBar.Delete
End If

'New bar
Set ofcBar = olkApp.ActiveExplorer.CommandBars.Add(CMDBAR_TITLE)
With ofcBar
    .Visible = True
End With

'Set Button
Set ofcButton = ofcBar.Controls.Add(msoControlButton)
With ofcButton
     'Change the caption on the next line.'
     .Caption = "ABRIR Chamado Service Desk"
     .HyperlinkType = msoCommandBarButtonHyperlinkOpen
     'Change the path to the template file on the next line.'
     .TooltipText = "" 'I DON'T KNOW WHAT TO PUT HERE
     .Visible = True
End With


olkSes.Logoff

Set olkSes = Nothing
Set olkApp = Nothing
Set ofcButton = Nothing
Set ofcPopup = Nothing
Set ofcBar = Nothing
Set objFD = Nothing
Set objItem = Nothing
Set fso = Nothing

Now the other exemple (Link above)  gave me the ability to Hyperlink a path to my desktop, for instance. But what I REALLY need is to that button opens the form that is already inside Outlook, on the personal registry!


Thank you all!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros