【发布时间】:2020-06-25 16:36:22
【问题描述】:
我正在尝试创建一个上下文菜单,以便当我右键单击某人的姓名时,它将查询网页以带回他们的 rolodex 信息。它不保存在本地联系人中。我在网页上有。
我有这个我发现并一直在使用(更大的子的sn-p),
' Configure the button to call the
' DisplayItemMetadata routine when
' clicked. The Parameter property of the
' button is set to the value of the
' EntryID property for the selected
' item, if possible.
With objButton
.Caption = "&Look Up Name"
.FaceId = 1000
.Tag = "DisplayItemMetadata"
If Not IsNull(Selection.Item(1)) Then
On Error GoTo 0
' Just in case the item selected
' doesn't have a valid EntryID.
.Parameter = Selection.Item(1).EntryID
On Error GoTo ErrRoutine
End If
'.OnAction = _
' "Project1.ThisOutlookSession.DisplayItemMetadata"
.OnAction = _
"NavigateToURL(""http://somewebsite"")"
End With
它从不调用 NavigateToURL 子。它从不调用该函数,因此我永远无法访问以下代码。没有错误。断点和调试显示它只是结束了 With 和 Sub。我试过用,
Call NavigateToURL(""http://somewebsite"")
NavigateToURL "http://somewebsite"
都不行。我得到Expected Expression。
Public Sub NavigateToURL(ByVal argURL As String)
MsgBox ("hi")
Const READYSTATE_COMPLETE As Integer = 4
Dim objIE As Object
Set objIE = CreateObject("InternetExplorer.Application")
With objIE
.Visible = False
.Silent = True
.Navigate argURL
Do Until .ReadyState = READYSTATE_COMPLETE
DoEvents
Loop
End With
objIE.Quit
Set objIE = Nothing
End Sub
如果有其他方法可以使用上下文菜单打开网页?工具提示?
编辑:对不起。我必须找到我得到它的地方。来自Microsoft。
Sub Application_ItemContextMenuDisplay( _
ByVal CommandBar As Office.CommandBar, _
ByVal Selection As Selection)
Dim objButton As Office.CommandBarButton
On Error GoTo ErrRoutine
If Selection.Count = 1 Then
' Add a new button to the bottom of the CommandBar
' (which represents the item context menu.)
Set objButton = CommandBar.Controls.Add( _
msoControlButton)
' Configure the button to call the
' DisplayItemMetadata routine when
' clicked. The Parameter property of the
' button is set to the value of the
' EntryID property for the selected
' item, if possible.
With objButton
.Caption = "&Display metadata"
.FaceId = 1000
.Tag = "DisplayItemMetadata"
If Not IsNull(Selection.Item(1)) Then
On Error GoTo 0
' Just in case the item selected
' doesn't have a valid EntryID.
.Parameter = Selection.Item(1).EntryID
On Error GoTo ErrRoutine
End If
.OnAction = _
"Project1.ThisOutlookSession.DisplayItemMetadata"
End With
End If
EndRoutine:
Exit Sub
ErrRoutine:
MsgBox Err.Number & " - " & Err.Description, _
vbOKOnly Or vbCritical, _
"Application_ItemContextMenuDisplay"
GoTo EndRoutine
End Sub
Private Sub DisplayItemMetadata()
Dim objNamespace As NameSpace
Dim objItem As Object
Dim strEntryID As String
On Error GoTo ErrRoutine
' Retrieve the value of the Parameter property from the
' control that called this routine.
strEntryID = _
Application.ActiveExplorer.CommandBars.ActionControl.Parameter
' If there's no entry ID, we can't easily retrieve the item.
If strEntryID = "" Then
MsgBox "An entry ID could not be retrieved from " & _
"the selected menu item."
Else
' Fetch an item reference using the specified entry ID.
Set objNamespace = Application.GetNamespace("MAPI")
Set objItem = objNamespace.GetItemFromID(strEntryID)
If objItem Is Nothing Then
MsgBox "A reference for the Outlook item " & _
"could not be retrieved."
Else
' Display information about the item.
MsgBox "Message Class: " & objItem.MessageClass & vbCrLf & _
"Size: " & objItem.Size
End If
End If
EndRoutine:
Set objItem = Nothing
Set objNamespace = Nothing
Exit Sub
ErrRoutine:
MsgBox Err.Number & " - " & Err.Description, _
vbOKOnly Or vbCritical, _
"DisplayItemMetadata"
GoTo EndRoutine
End Sub
【问题讨论】:
-
您注释掉的示例代码使用不同的结构来命名
OnAction过程:Project1.ThisOutlookSession...也许您遗漏了什么?由于网站似乎没有动态变化,您可能也希望在NavigateToURL过程中使用Const,而不是将其作为参数发送(我认为这可能很棘手,因为您必须将其串起来) . -
如何使用 .onAction(或其他方法)打开网页?
-
您注释掉的示例代码使用不同的结构来命名 OnAction 过程:Project1.ThisOutlookSession... 也许您的代码不完整?
-
@DavidZemens 我第一次读到它。我保证。我将阅读更多关于 .OnAction 的内容,因为我不明白你想说什么。