先上效果图
再上代码
Public Class ThisAddIn
Public WithEvents AboutTaskPan As Microsoft.Office.Tools.CustomTaskPane
Dim userAbout As New UserControl2
Dim sheet As Excel.Worksheet
Private Sub ThisAddIn_Startup() Handles Me.Startup
' 获取当前活动的工作表
sheet = Globals.ThisAddIn.Application.ActiveSheet
' 为SelectionChange事件添加事件处理器
AddHandler sheet.SelectionChange, AddressOf Sheet_SelectionChange
Debug.WriteLine(sheet.Name)
'MessageBox.Show(sheet.Name)
AboutTaskPan = Globals.ThisAddIn.CustomTaskPanes.Add(userAbout, "查询库存")
AboutTaskPan.Width = 840
AboutTaskPan.Visible = False
AboutTaskPan.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionRight
'添加自定义任务面板,将会显示