如何使用 VBA 在 Outlook 2007 中的超链接菜单中添加新项目?

发布于 2024-10-30 06:05:04 字数 123 浏览 5 评论 0原文

我需要向 Outlook 2007 中的超链接菜单添加新项目(现在它包含“复制”、“选择超链接”、“打开超链接”、“复制超链接”、“谁是”等项目)。

我该怎么做呢? (它应该是添加到 Outlook 的 VBA 宏)

I need to add new item to the hyperlink menu in Outlook 2007 (now it contains items like Copy, Select Hyperlink, Open Hyperlink, Copy Hyperlink, Who is).

How can I do it?
(it should be a VBA macro added to Outlook)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

倾城泪 2024-11-06 06:05:05

看来VBA 没有办法做同样的事情。连MS也没有答案。

Looks like there is no way to do the same with VBA. Even MS doesn't have an answer.

—━☆沉默づ 2024-11-06 06:05:05

有关 Outlook 和 CommandBar 对象的权威文章位于此处

您可以在 Excel 中运行本文末尾的代码来获取所有 CommandBar 对象的列表,如下所示。请注意,您必须在 VBA 的参考中拥有 Outlook 库才能运行它: 对

Option Explicit
Dim oOutApp As Outlook.Application
Dim I As Long
Dim iRowCount As Long
Dim oItm As Object ' so it'll handle varying item types
Dim oSheet As Excel.Worksheet
Dim oNS As Outlook.NameSpace
Dim oFld As Outlook.MAPIFolder

Sub GetOutlookCommandBarIDs()

If MsgBox("This will clear the current worksheet, OK to continue?", vbOKCancel) = 1 Then

   Cells.Select
   Selection.ClearContents

   iRowCount = 0
   Set oSheet = ActiveSheet
   Set oOutApp = New Outlook.Application
   Set oNS = oOutApp.Session

   Set oItm = oOutApp.CreateItem(olMailItem)
   GetInspectorIDs oItm, "Mail Message"
   Set oItm = oOutApp.CreateItem(olPostItem)
   GetInspectorIDs oItm, "Post"
   Set oItm = oOutApp.CreateItem(olContactItem)
   GetInspectorIDs oItm, "Contact"
   Set oItm = oOutApp.CreateItem(olDistributionListItem)
   GetInspectorIDs oItm, "Distribution List"
   Set oItm = oOutApp.CreateItem(olAppointmentItem)
   GetInspectorIDs oItm, "Appointment"
   Set oItm = oOutApp.CreateItem(olTaskItem)
   GetInspectorIDs oItm, "Task"
   Set oItm = oOutApp.CreateItem(olJournalItem)
   GetInspectorIDs oItm, "Journal Entry"

   Set oFld = oNS.GetDefaultFolder(olFolderInbox)
   GetExplorerIDs oFld, "Mail Folder"
   Set oFld = oNS.GetDefaultFolder(olFolderContacts)
   GetExplorerIDs oFld, "Contact Folder"
   Set oFld = oNS.GetDefaultFolder(olFolderCalendar)
   GetExplorerIDs oFld, "Calendar Folder"
   Set oFld = oNS.GetDefaultFolder(olFolderTasks)
   GetExplorerIDs oFld, "Task Folder"
   Set oFld = oNS.GetDefaultFolder(olFolderJournal)
   GetExplorerIDs oFld, "Journal Folder"
   Set oFld = oNS.GetDefaultFolder(olFolderNotes)
   GetExplorerIDs oFld, "Notes Folder"

   Selection.AutoFilter
   Cells.Select
   Cells.EntireColumn.AutoFit
   Range("A1").Select

   MsgBox "The spreadsheet is complete."

End If

End Sub


Sub GetInspectorIDs(oItm, sType As String)
   Dim oCBs As Office.CommandBars
   Dim oCtl As Office.CommandBarControl
   Set oCBs = oItm.GetInspector.CommandBars
   For I = 1 To 35000
      Set oCtl = oCBs.FindControl(, I)
      If Not (oCtl Is Nothing) Then
         iRowCount = iRowCount + 1
         oSheet.Cells(iRowCount, 1) = "Inspector"
         oSheet.Cells(iRowCount, 2) = sType
         oSheet.Cells(iRowCount, 3) = oCtl.Parent.Name
         oSheet.Cells(iRowCount, 4) = oCtl.Caption
         oSheet.Cells(iRowCount, 5) = CStr(I)
      End If
   Next
End Sub


Sub GetExplorerIDs(oFld As Outlook.MAPIFolder, sType As String)
   Dim oCBs As Office.CommandBars
   Dim sFilter As String
   Dim oCtl As Office.CommandBarControl
   Set oCBs = oFld.GetExplorer.CommandBars
   For I = 1 To 35000
      Set oCtl = oCBs.FindControl(, I)
      If Not (oCtl Is Nothing) Then
         iRowCount = iRowCount + 1
         oSheet.Cells(iRowCount, 1) = "Explorer"
         oSheet.Cells(iRowCount, 2) = sType
         oSheet.Cells(iRowCount, 3) = oCtl.Parent.Name
         oSheet.Cells(iRowCount, 4) = oCtl.Caption
         oSheet.Cells(iRowCount, 5) = CStr(I)
      End If
   Next
End Sub

您有帮助的输出摘录如下:

Inspector   Mail Message    Insert  Te&xt Box          139
Inspector   Mail Message    Insert  &Symbol...         308
Inspector   Mail Message    Insert  &Tip Wizard 5      345
Inspector   Mail Message    Insert  &Object...         546
Inspector   Mail Message    Insert  Boo&kmark...       758
Inspector   Mail Message    Insert  Date and &Time...  768
Inspector   Mail Message    Insert  &Field...          772
Inspector   Mail Message    Insert  Attach             1079
Inspector   Mail Message    Insert  &Hyperlink...      1576
Inspector   Mail Message    Insert  New Co&mment       1589
Inspector   Mail Message    Insert  It&em...           2505
Inspector   Mail Message    Insert  &Remove Hyperlink  3626
Inspector   Mail Message    Insert  &Calendar...       11496
Inspector   Mail Message    Insert  &Picture           30180

因此,您可以像这样访问它:

 Dim oItm As Object
 Dim oExp As Outlook.Explorer
 Dim oBar As Office.CommandBar
 Dim oOutApp As Object

 Set oOutApp = CreateObject("Outlook.Application")

 Set oItm = oOutApp.CreateItem(olMailItem)
 Set oExp = Outlook.ActiveExplorer
 Set oBar = oItm.GetInspector.CommandBars.Item("Insert")

 oBar.Controls.Add (blahblahblah)

注意: I只能在 Outlook 2010 中进行测试。

The definitive article on Outlook and CommandBar objects is here.

The code at the end of the article that you can run in Excel to get a listing of all the CommandBar objects is following. Note that you have to have the Outlook Library in the References in VBA to get this to run:

Option Explicit
Dim oOutApp As Outlook.Application
Dim I As Long
Dim iRowCount As Long
Dim oItm As Object ' so it'll handle varying item types
Dim oSheet As Excel.Worksheet
Dim oNS As Outlook.NameSpace
Dim oFld As Outlook.MAPIFolder

Sub GetOutlookCommandBarIDs()

If MsgBox("This will clear the current worksheet, OK to continue?", vbOKCancel) = 1 Then

   Cells.Select
   Selection.ClearContents

   iRowCount = 0
   Set oSheet = ActiveSheet
   Set oOutApp = New Outlook.Application
   Set oNS = oOutApp.Session

   Set oItm = oOutApp.CreateItem(olMailItem)
   GetInspectorIDs oItm, "Mail Message"
   Set oItm = oOutApp.CreateItem(olPostItem)
   GetInspectorIDs oItm, "Post"
   Set oItm = oOutApp.CreateItem(olContactItem)
   GetInspectorIDs oItm, "Contact"
   Set oItm = oOutApp.CreateItem(olDistributionListItem)
   GetInspectorIDs oItm, "Distribution List"
   Set oItm = oOutApp.CreateItem(olAppointmentItem)
   GetInspectorIDs oItm, "Appointment"
   Set oItm = oOutApp.CreateItem(olTaskItem)
   GetInspectorIDs oItm, "Task"
   Set oItm = oOutApp.CreateItem(olJournalItem)
   GetInspectorIDs oItm, "Journal Entry"

   Set oFld = oNS.GetDefaultFolder(olFolderInbox)
   GetExplorerIDs oFld, "Mail Folder"
   Set oFld = oNS.GetDefaultFolder(olFolderContacts)
   GetExplorerIDs oFld, "Contact Folder"
   Set oFld = oNS.GetDefaultFolder(olFolderCalendar)
   GetExplorerIDs oFld, "Calendar Folder"
   Set oFld = oNS.GetDefaultFolder(olFolderTasks)
   GetExplorerIDs oFld, "Task Folder"
   Set oFld = oNS.GetDefaultFolder(olFolderJournal)
   GetExplorerIDs oFld, "Journal Folder"
   Set oFld = oNS.GetDefaultFolder(olFolderNotes)
   GetExplorerIDs oFld, "Notes Folder"

   Selection.AutoFilter
   Cells.Select
   Cells.EntireColumn.AutoFit
   Range("A1").Select

   MsgBox "The spreadsheet is complete."

End If

End Sub


Sub GetInspectorIDs(oItm, sType As String)
   Dim oCBs As Office.CommandBars
   Dim oCtl As Office.CommandBarControl
   Set oCBs = oItm.GetInspector.CommandBars
   For I = 1 To 35000
      Set oCtl = oCBs.FindControl(, I)
      If Not (oCtl Is Nothing) Then
         iRowCount = iRowCount + 1
         oSheet.Cells(iRowCount, 1) = "Inspector"
         oSheet.Cells(iRowCount, 2) = sType
         oSheet.Cells(iRowCount, 3) = oCtl.Parent.Name
         oSheet.Cells(iRowCount, 4) = oCtl.Caption
         oSheet.Cells(iRowCount, 5) = CStr(I)
      End If
   Next
End Sub


Sub GetExplorerIDs(oFld As Outlook.MAPIFolder, sType As String)
   Dim oCBs As Office.CommandBars
   Dim sFilter As String
   Dim oCtl As Office.CommandBarControl
   Set oCBs = oFld.GetExplorer.CommandBars
   For I = 1 To 35000
      Set oCtl = oCBs.FindControl(, I)
      If Not (oCtl Is Nothing) Then
         iRowCount = iRowCount + 1
         oSheet.Cells(iRowCount, 1) = "Explorer"
         oSheet.Cells(iRowCount, 2) = sType
         oSheet.Cells(iRowCount, 3) = oCtl.Parent.Name
         oSheet.Cells(iRowCount, 4) = oCtl.Caption
         oSheet.Cells(iRowCount, 5) = CStr(I)
      End If
   Next
End Sub

The excerpt of the output that will help you is:

Inspector   Mail Message    Insert  Te&xt Box          139
Inspector   Mail Message    Insert  &Symbol...         308
Inspector   Mail Message    Insert  &Tip Wizard 5      345
Inspector   Mail Message    Insert  &Object...         546
Inspector   Mail Message    Insert  Boo&kmark...       758
Inspector   Mail Message    Insert  Date and &Time...  768
Inspector   Mail Message    Insert  &Field...          772
Inspector   Mail Message    Insert  Attach             1079
Inspector   Mail Message    Insert  &Hyperlink...      1576
Inspector   Mail Message    Insert  New Co&mment       1589
Inspector   Mail Message    Insert  It&em...           2505
Inspector   Mail Message    Insert  &Remove Hyperlink  3626
Inspector   Mail Message    Insert  &Calendar...       11496
Inspector   Mail Message    Insert  &Picture           30180

So you'd access it something like:

 Dim oItm As Object
 Dim oExp As Outlook.Explorer
 Dim oBar As Office.CommandBar
 Dim oOutApp As Object

 Set oOutApp = CreateObject("Outlook.Application")

 Set oItm = oOutApp.CreateItem(olMailItem)
 Set oExp = Outlook.ActiveExplorer
 Set oBar = oItm.GetInspector.CommandBars.Item("Insert")

 oBar.Controls.Add (blahblahblah)

Note: I was only able to test things in Outlook 2010.

终弃我 2024-11-06 06:05:05

抱歉,我没有给您明确的答案,但希望我能为您指出正确的方向。

希望这个论坛有用,看起来他们在那里做同样的事情(尽管菜单不同)。

如果您需要一些基础知识帮助,这里有两个 MSDN 博客,一般讨论 Outlook 和 VBA 宏:
http:// /blogs.msdn.com/b/synergist/archive/2007/05/23/adding-a-vba-macro-to-outlook.aspx

希望这有帮助!

Sorry I don't have a definite answer for you, but hopefully I can point you in the right direction.

This forum will hopefully be useful, it looks like they're doing the same thing there (albeit with a different menu).

And if you need some basics help, here are two MSDN blogs talking about Outlook and VBA macros in general:
http://blogs.msdn.com/b/synergist/archive/2007/05/23/adding-a-vba-macro-to-outlook.aspx
http://blogs.msdn.com/b/swiss_dpe_team/archive/2007/12/11/office-2007-outlook2007-macros-vba-how-to-work-better-with-categories.aspx

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文