p;= CType(ex.CommandBars.Add(toolbarName,
Microsoft.Office.Core.MsoBarPosition.msoBarTop, , True),
Microsoft.Office.Core.CommandBar)
toolBar.Visible = True
Return toolBar
Catch
Return Nothing
End Try
End Function
’在工具栏上添加一个按钮
Private Function MakeANewButton()Function MakeANewButton(ByVal commandBar As Microsoft.Office.Core.CommandBar, ByVal caption
As String, ByVal faceID As Integer, ByVal clickHandler As Microsoft.Office.
Core._CommandBarButtonEvents_ClickEventHandler) As Microsoft.Office.Core.CommandBarButton
Try
Dim newButton As Microsoft.Office.Core.CommandBarButton
newButton = CType(commandBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton), Microsoft.Office.Core.CommandBarButton)
newButton.Caption = caption
newButton.FaceId = faceID
AddHandler newButton.Click, clickHandler
Return newButton
Catch ex As System.Exception
Return Nothing
End Try
End Function
’点击工具条按钮时应该执行的
程序 Public Sub pasteText_Click()Sub pasteText_Click(ByVal barButton As Microsoft.Office.Core.CommandBarButton, ByRef someBool As Boolean)
Dim text As String = ""
Dim data As System.Windows.Forms.IDataObject = System.Windows.Forms.Clipboard.GetDataObject()
If data.GetDataPresent(System.Windows.Forms.DataFormats.Text) Then
text = data.GetData(System.Windows.Forms.DataFormats.Text).ToString()
If (Not app Is Nothing) Then
Me.app.ActiveCell.Value = text
End If
End If
End Sub
End Class
这样
程序就完成了,赶紧动手体验吧!