Avatar of Rafael Adamska
Rafael Adamska
Flag for Brazil

asked on 

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

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?anchorAnswerId=26403266#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

Open in new window


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!
VB ScriptOutlookVisual Basic ClassicVBA

Avatar of undefined
Last Comment
Chris Raisin

8/22/2022 - Mon