这里我创建了Outlook添加。在这里我创建一个菜单栏项目并在菜单栏上添加一个按钮。当我运行应用程序时,我得到一个运行时错误“值不在预期范围内” MyMenuBar()方法初始化_objNewMenuBar。可以任何人建议我为什么给我这样的类型或错误。这是一个堆栈跟踪值,我得到错误
at Microsoft.Office.Core.CommandBarControls.Add(Object Type,Object Id,Object Parameter,Object Before,Object Temporary)
在TROutlookAddOn.ThisAddIn.MyMenuBar()
Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
Me.MyMenuBar()
End Sub
Private Sub MyMenuBar()
Me.ErsMyMenuBar()
Try
'Define the existent Menu Bar
_objMenuBar = Me.Application.ActiveExplorer.CommandBars.ActiveMenuBar
'Define the new Menu Bar into the old menu bar
_objNewMenuBar = CType(_objMenuBar.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, missing, False), Office.CommandBarPopup)
If (Not (_objNewMenuBar) Is Nothing) Then
_objNewMenuBar.Caption = "Talent Recruit"
_objNewMenuBar.Tag = menuTag
_objButton = CType(_objNewMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, 1, True), Office.CommandBarButton)
_objButton.Caption = "Import Resume"
Dim newIcon As System.Drawing.Icon = My.Resources.recruit_logo
Dim newImageList As ImageList = New ImageList
newImageList.Images.Add(newIcon)
_objButton.Picture = ConvertImage.Convert(newImageList.Images(0))
_objButton.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption
'Icon
'_objButton.FaceId = 500;
_objButton.Tag = "ItemTag"
'EventHandler
AddHandler _objButton.Click, AddressOf Me._objButton_Click
_objNewMenuBar.Visible = True
End If
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(("Error: " + ex.Message.ToString), "Error Message")
End Try
End Sub
答案 0 :(得分:0)
从方法
中删除所有缺失变量的解决方案