Rob
Rob

Reputation: 53

Outlook 2013 VBA: store user defined settings

Currently at the office we have Outlook 2003. We will be migrating to Outlook 2013. In Outlook 2003 we have a commandbar that as example saves a mail item to a user specified folder or moves the item to the desired team. In a userform the end-user can set his settings to his desired folder or select the team he is currently on. In this settings form there are multiple input field the user can fillout. Whenever he clicks a button on the commandbar, outlook checks his settings to see on what team he is on, his desired save folder is, etc. This userdefined settings are stored and called on by it's tags (Application.ActiveExplorer.CommandBars("Toolbar").Controls.Item(1).tag)

As far i found on the internet Outlook 2013 does not support commandbars. I can instal the commandBar, but as soon as you restart outlook the bar is gone and the settings are gone.

Is there a way to save/store the settings made by the end-user in a userform so the scripts saves the mail item based on his settings to the correct folder or team?

I've tried to find a solution but haven't found it yet, or do not know where to look.

Hope you can guide me into the right direction to look for a solution.

(note: I know a little bit of VBA, can read and write it, but found it hard to explain how it works. If i left out some critical information in the question please let me know.)

Upvotes: 3

Views: 1779

Answers (3)

Christian Geiselmann
Christian Geiselmann

Reputation: 622

If I understand your problem correctly, what I would do is the following:

1) Export your VBA stuff into a *.bas files (for modules) and *.frx (for user forms) This is done in the VBA editor, File --> Export. You do this for each item (module and user form). Save these files e.g. on a memory stick, or whereever it suits you.

2) Import these files in Outlook 2013 into the VBA editor (same way, but --> File --> Import of course) e.g. by loading them from your memory stick.

This should make your VBA code available in your new Outlook 2013 environment.

3) Your command bars will not be available. But you can easily create something else: In the Office 2013 (etc.) products, you can add stuff to the "Ribbon". E.g. you can create a new tab called "My self-made tools", and you can place buttons there that call your VBA procedures. There you will find buttons for "Create new..."

To do so: --> File --> Optiobs --> Customize Ribbon --> Macros

Note: In a standard installation of Office 2013 (etc.) you will not have access to the VBA editor. To make the editor available, go through --> File --> Options --> Customize Ribbon and set a tick mark in the field for "Develooper tools". This will make a tab of that name appear in the "Ribbon".

Upvotes: 0

Rob
Rob

Reputation: 53

As promised a few code samples wich i used to store and get the settings. Maybe not the best way to do it, but it solved my problem to store the settings and maybe it could help someone else.

First of all I made a little check to see if the settings are already there.

Function Hidden_Settings_Aanwezig() As Boolean

Dim oNs As Outlook.Namespace
Dim oFL As Outlook.folder
Dim oItem As Outlook.StorageItem

On Error GoTo OL_Error

Set oNs = Application.GetNamespace("MAPI")
Set oFld = oNs.GetDefaultFolder(olFolderInbox)
Set oItem = oFld.GetStorage("Hidden Settings", olIdentifyBySubject)

If oItem.Size <> 0 Then
    Hidden_Settings_Aanwezig = True
    Else
    Hidden_Settings_Aanwezig = False
End If

Exit Function
OL_Error:
MsgBox (Err.Description)
Err.Clear

End Function

If not, the following code creates the settings based on tekstboxes and checkboxes on a userform with the following code

Function Maak_Settings_Hidden()

Dim oNs As Outlook.Namespace
Dim oFld As Outlook.folder
Dim oSItem As Outlook.StorageItem

On Error GoTo OL_Error

Set oFld = Application.Session.GetDefaultFolder(olFolderInbox)
Set oSItem = oFld.GetStorage("Hidden Settings", olIdentifyBySubject)

'repeat the next to lines for every setting you want to store
oSItem.UserProperties.Add "Export Folder", olText
oSItem.UserProperties("Export Folder").Value = TextBox1.Text

oSItem.Save

Exit Function
OL_Error:
MsgBox (Err.Description)
Err.Clear

End Function

The functions above are called on with the following code:

If Hidden_Settings_Aanwezig = True Then
   Call Get_Hidden_Settings_Startup
Else
   Maak_Settings_Hidden
End If

To use one of the settings i use the following code. In the main sub I use the following line:

DestFolder = Get_Hidden_Settings("Export Folder")

To call on this function:

Function Get_Hidden_Settings(Setting) As String

Dim oNs As Outlook.Namespace
Dim oFL As Outlook.folder
Dim oItem As Outlook.StorageItem

On Error GoTo OL_Error

Set oNs = Application.GetNamespace("MAPI")
Set oFld = oNs.GetDefaultFolder(olFolderInbox)
Set oItem = oFld.GetStorage("Hidden Settings", olIdentifyBySubject)

If oItem.Size <> 0 Then
    Get_Hidden_Settings = oItem.UserProperties(Setting)
End If

Exit Function
OL_Error:
MsgBox (Err.Description)
Err.Clear

End Function

Upvotes: 1

Eugene Astafiev
Eugene Astafiev

Reputation: 49405

Outlook doesn't allow to customize the Ribbon UI using VBA. The only thing you can do is to assign a macro to QAT button (or add controls manually in Outlook).

You need to develop an add-in to be able to customize the Ribbon UI (aka Fluent UI). See Walkthrough: Creating a Custom Tab by Using the Ribbon Designer for more information.

Read more about the Fluent UI in the following series of articles in MSDN:

Is there a way to save/store the settings made by the end-user in a userform so the scripts saves the mail item based on his settings to the correct folder or team?

Using the Tag property is not the best way to store the user settings. Of course, you can standard ways for storing settings on the PC - files (XML, text or your own binary format), windows registry and etc.

But the Outlook object model provides hidden items for that. The GetStorage method of the Folder class returns a StorageItem object on the parent Folder to store data for an Outlook solution. See Storing Data for Solutions for more information.

Upvotes: 1

Related Questions