我需要在Outlook 2007的超链接菜单中添加新项目(现在它包含复制,选择超链接,打开超链接,复制超链接,谁是)等项目。
我该怎么办? (它应该是添加到Outlook的VBA宏)
答案 0 :(得分:3)
看起来没有办法对VBA做同样的事情。即便是MS也没有答案。
答案 1 :(得分:2)
有关Outlook和CommandBar对象的权威文章是here。
本文末尾的代码可以在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)
注意:我只能在Outlook 2010中测试内容。
答案 2 :(得分:0)
答案 3 :(得分:0)
对不起,我没有给你一个明确的答案,但希望我能指出你正确的方向。
This forum will hopefully be useful,看起来他们在那里做同样的事情(虽然有不同的菜单)。
如果你需要一些基础帮助,这里有两个MSDN博客,一般都在讨论Outlook和VBA宏:
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
希望这有帮助!