Outlook 2013 VBA:存储用户定义的设置
Outlook 2013 VBA: store user defined settings
目前我们办公室有 Outlook 2003。我们将迁移到 Outlook 2013。
在 Outlook 2003 中,我们有一个命令栏,例如将邮件项目保存到用户指定的文件夹或将项目移动到所需的团队。
在用户表单中,最终用户可以将他的设置设置为他想要的文件夹或 select 他当前所在的团队。在此设置表单中,用户可以填写多个输入字段。
每当他单击命令栏上的按钮时,outlook 都会检查他的设置以查看他在哪个团队,他想要的保存文件夹等。
此用户定义的设置由其标签存储和调用
(Application.ActiveExplorer.CommandBars("Toolbar").Controls.Item(1).tag)
据我所知,在 Internet 上发现 Outlook 2013 不支持命令栏。我可以安装 commandBar,但是只要您重新启动 outlook,该栏就消失了,设置也消失了。
有没有办法 save/store 最终用户在用户表单中所做的设置,以便脚本根据他的设置将邮件项目保存到正确的文件夹或团队?
我试图找到解决方案,但尚未找到,或者不知道去哪里寻找。
希望您能引导我朝着正确的方向寻找解决方案。
(注意:我对VBA略知一二,可以读写,但很难解释它是如何工作的。如果我遗漏了一些关键信息有问题请告诉我。)
Outlook 不允许使用 VBA 自定义功能区 UI。您唯一可以做的就是为 QAT 按钮分配一个宏(或在 Outlook 中手动添加控件)。
您需要开发一个插件才能自定义功能区 UI(又名 Fluent UI)。有关详细信息,请参阅 Walkthrough: Creating a Custom Tab by Using the Ribbon Designer。
在 MSDN 中的以下系列文章中阅读有关 Fluent UI 的更多信息:
- Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
- Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
- Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)
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?
使用标签 属性 不是存储用户设置的最佳方式。当然,您可以使用标准方式在 PC 上存储设置 - 文件(XML、文本或您自己的二进制格式)、windows 注册表等
但是 Outlook 对象模型为此提供了隐藏项。 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 了解更多信息。
正如承诺的那样,我使用了一些代码示例来存储和获取设置。
也许不是最好的方法,但它解决了我存储设置的问题,也许它可以帮助其他人。
首先,我稍微检查了一下设置是否已经存在。
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
如果没有,以下代码使用以下代码创建基于用户窗体上的 tekstboxes 和复选框的设置
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
以上函数使用以下代码调用:
If Hidden_Settings_Aanwezig = True Then
Call Get_Hidden_Settings_Startup
Else
Maak_Settings_Hidden
End If
要使用其中一种设置,我使用以下代码。
在主子中,我使用以下行:
DestFolder = Get_Hidden_Settings("Export Folder")
要调用此函数:
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
如果我正确理解你的问题,我会做的是:
1) 将您的 VBA 内容导出到 *.bas 文件(用于模块)和 *.frx(用于用户表单)这是在 VBA 编辑器中完成的,文件 -->出口。您为每个项目(模块和用户表单)执行此操作。保存这些文件,例如在记忆棒上,或任何适合您的地方。
2) 将 Outlook 2013 中的这些文件导入 VBA 编辑器(方法相同,当然是 --> 文件 --> 导入)例如通过从记忆棒加载它们。
这应该使您的 VBA 代码在新的 Outlook 2013 环境中可用。
3) 您的命令栏将不可用。但您可以轻松创建其他内容:在 Office 2013(等)产品中,您可以向 "Ribbon" 添加内容。例如。您可以创建一个名为 "My self-made tools" 的新选项卡,并且可以在其中放置调用 VBA 过程的按钮。在那里你会找到 "Create new..."
的按钮
为此:--> 文件 --> 选项 --> 自定义功能区 --> 宏
注意:在 Office 2013(等)的标准安装中,您将无法访问 VBA 编辑器。要使编辑器可用,请通过 --> 文件 --> 选项 --> 自定义功能区并在 "Develooper tools" 字段中设置勾号。这将使该名称的选项卡出现在 "Ribbon".
中
目前我们办公室有 Outlook 2003。我们将迁移到 Outlook 2013。
在 Outlook 2003 中,我们有一个命令栏,例如将邮件项目保存到用户指定的文件夹或将项目移动到所需的团队。
在用户表单中,最终用户可以将他的设置设置为他想要的文件夹或 select 他当前所在的团队。在此设置表单中,用户可以填写多个输入字段。
每当他单击命令栏上的按钮时,outlook 都会检查他的设置以查看他在哪个团队,他想要的保存文件夹等。
此用户定义的设置由其标签存储和调用
(Application.ActiveExplorer.CommandBars("Toolbar").Controls.Item(1).tag)
据我所知,在 Internet 上发现 Outlook 2013 不支持命令栏。我可以安装 commandBar,但是只要您重新启动 outlook,该栏就消失了,设置也消失了。
有没有办法 save/store 最终用户在用户表单中所做的设置,以便脚本根据他的设置将邮件项目保存到正确的文件夹或团队?
我试图找到解决方案,但尚未找到,或者不知道去哪里寻找。
希望您能引导我朝着正确的方向寻找解决方案。
(注意:我对VBA略知一二,可以读写,但很难解释它是如何工作的。如果我遗漏了一些关键信息有问题请告诉我。)
Outlook 不允许使用 VBA 自定义功能区 UI。您唯一可以做的就是为 QAT 按钮分配一个宏(或在 Outlook 中手动添加控件)。
您需要开发一个插件才能自定义功能区 UI(又名 Fluent UI)。有关详细信息,请参阅 Walkthrough: Creating a Custom Tab by Using the Ribbon Designer。
在 MSDN 中的以下系列文章中阅读有关 Fluent UI 的更多信息:
- Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
- Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
- Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)
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?
使用标签 属性 不是存储用户设置的最佳方式。当然,您可以使用标准方式在 PC 上存储设置 - 文件(XML、文本或您自己的二进制格式)、windows 注册表等
但是 Outlook 对象模型为此提供了隐藏项。 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 了解更多信息。
正如承诺的那样,我使用了一些代码示例来存储和获取设置。 也许不是最好的方法,但它解决了我存储设置的问题,也许它可以帮助其他人。
首先,我稍微检查了一下设置是否已经存在。
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
如果没有,以下代码使用以下代码创建基于用户窗体上的 tekstboxes 和复选框的设置
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
以上函数使用以下代码调用:
If Hidden_Settings_Aanwezig = True Then
Call Get_Hidden_Settings_Startup
Else
Maak_Settings_Hidden
End If
要使用其中一种设置,我使用以下代码。 在主子中,我使用以下行:
DestFolder = Get_Hidden_Settings("Export Folder")
要调用此函数:
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
如果我正确理解你的问题,我会做的是:
1) 将您的 VBA 内容导出到 *.bas 文件(用于模块)和 *.frx(用于用户表单)这是在 VBA 编辑器中完成的,文件 -->出口。您为每个项目(模块和用户表单)执行此操作。保存这些文件,例如在记忆棒上,或任何适合您的地方。
2) 将 Outlook 2013 中的这些文件导入 VBA 编辑器(方法相同,当然是 --> 文件 --> 导入)例如通过从记忆棒加载它们。
这应该使您的 VBA 代码在新的 Outlook 2013 环境中可用。
3) 您的命令栏将不可用。但您可以轻松创建其他内容:在 Office 2013(等)产品中,您可以向 "Ribbon" 添加内容。例如。您可以创建一个名为 "My self-made tools" 的新选项卡,并且可以在其中放置调用 VBA 过程的按钮。在那里你会找到 "Create new..."
的按钮为此:--> 文件 --> 选项 --> 自定义功能区 --> 宏
注意:在 Office 2013(等)的标准安装中,您将无法访问 VBA 编辑器。要使编辑器可用,请通过 --> 文件 --> 选项 --> 自定义功能区并在 "Develooper tools" 字段中设置勾号。这将使该名称的选项卡出现在 "Ribbon".
中