8 个解决方案
#1
Public Sub OnAddInsUpdate(ByRef custom As Array) Implements IDTExtensibility2.OnAddInsUpdate
End Sub
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)
http://feiyun0112.cnblogs.com/
End Sub
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)
http://feiyun0112.cnblogs.com/
#2
代码窗口顶部有两个下拉框,
左边一个叫 Object,选 IDTExtensibility2;
右边一个叫 Procedure,将所有的方法都选一遍。
会自动添加类似下面的空白实现
左边一个叫 Object,选 IDTExtensibility2;
右边一个叫 Procedure,将所有的方法都选一遍。
会自动添加类似下面的空白实现
private sub IDTExtensibility2_OnAddinsUpdate()
end sub
#3
多谢两位朋友的回答。现在已经可以运行,但再请教两个问题:
1.现在新建的工具栏只有一项,怎样创建更多?
2.如果我想把新建工具栏内容显示成图标,应如何设置?我曾把代码中“.Style = msoButtonCaption”改成“.Style = msoButtonIcon”,但再执行“Set .Picture = LoadPicture("D:\XXX.ico")”时提示“属性的使用无效”
代码不多,麻烦各位朋友给看看,谢谢!
Implements IDTExtensibility2
'Global object references
Public appHostApp As Excel.Application
Private WithEvents cbbButton As Office.CommandBarButton
Private Sub cbbButton_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
MsgBox ("Hello World!")
End Sub
Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
' 存储启动引用
Set appHostApp = Application
' 添加命令条
Set cbbButton = CreateBar()
End Sub
Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
RemoveToolbar
' 移除要关闭的引用
Set appHostApp = Nothing
Set cbbButton = Nothing
End Sub
Public Function CreateBar() As Office.CommandBarButton
' 指定命令条
Dim cbcMyBar As Office.CommandBar
Dim btnMyButton As Office.CommandBarButton
On Error GoTo CreateBar_Err
Set cbcMyBar = appHostApp.CommandBars.Add(Name:="GreetingBar")
' 指定命令条按钮
Set btnMyButton = cbcMyBar.Controls.Add(Type:=msoControlButton, _
Parameter:="Greetings")
With btnMyButton
.Style = msoButtonCaption
.BeginGroup = True
.Caption = "&Greetings"
.ToolTipText = "Display Hello World Message"
.Width = "24"
End With
' 显示并返回命令条
cbcMyBar.Visible = True
Set CreateBar = btnMyButton
Exit Function
CreateBar_Err:
MsgBox Err.Number & vbCrLf & Err.Description
End Function
Private Function RemoveToolbar()
appHostApp.CommandBars("GreetingBar").Delete
End Function
Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
End Sub
1.现在新建的工具栏只有一项,怎样创建更多?
2.如果我想把新建工具栏内容显示成图标,应如何设置?我曾把代码中“.Style = msoButtonCaption”改成“.Style = msoButtonIcon”,但再执行“Set .Picture = LoadPicture("D:\XXX.ico")”时提示“属性的使用无效”
代码不多,麻烦各位朋友给看看,谢谢!
Implements IDTExtensibility2
'Global object references
Public appHostApp As Excel.Application
Private WithEvents cbbButton As Office.CommandBarButton
Private Sub cbbButton_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
MsgBox ("Hello World!")
End Sub
Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
' 存储启动引用
Set appHostApp = Application
' 添加命令条
Set cbbButton = CreateBar()
End Sub
Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
RemoveToolbar
' 移除要关闭的引用
Set appHostApp = Nothing
Set cbbButton = Nothing
End Sub
Public Function CreateBar() As Office.CommandBarButton
' 指定命令条
Dim cbcMyBar As Office.CommandBar
Dim btnMyButton As Office.CommandBarButton
On Error GoTo CreateBar_Err
Set cbcMyBar = appHostApp.CommandBars.Add(Name:="GreetingBar")
' 指定命令条按钮
Set btnMyButton = cbcMyBar.Controls.Add(Type:=msoControlButton, _
Parameter:="Greetings")
With btnMyButton
.Style = msoButtonCaption
.BeginGroup = True
.Caption = "&Greetings"
.ToolTipText = "Display Hello World Message"
.Width = "24"
End With
' 显示并返回命令条
cbcMyBar.Visible = True
Set CreateBar = btnMyButton
Exit Function
CreateBar_Err:
MsgBox Err.Number & vbCrLf & Err.Description
End Function
Private Function RemoveToolbar()
appHostApp.CommandBars("GreetingBar").Delete
End Function
Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
End Sub
#4
学习
#5
继承了一个接口,那么即便某个方法下面没有处理代码,也要保证这个"接口"的完整性.
#6
还有一个问题,上述代码实现了一个工具栏中的一个按钮,但不知道怎样实现菜单?希望高手指教,谢谢!
#7
学习
#8
谢谢,学习了
#1
Public Sub OnAddInsUpdate(ByRef custom As Array) Implements IDTExtensibility2.OnAddInsUpdate
End Sub
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)
http://feiyun0112.cnblogs.com/
End Sub
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)
http://feiyun0112.cnblogs.com/
#2
代码窗口顶部有两个下拉框,
左边一个叫 Object,选 IDTExtensibility2;
右边一个叫 Procedure,将所有的方法都选一遍。
会自动添加类似下面的空白实现
左边一个叫 Object,选 IDTExtensibility2;
右边一个叫 Procedure,将所有的方法都选一遍。
会自动添加类似下面的空白实现
private sub IDTExtensibility2_OnAddinsUpdate()
end sub
#3
多谢两位朋友的回答。现在已经可以运行,但再请教两个问题:
1.现在新建的工具栏只有一项,怎样创建更多?
2.如果我想把新建工具栏内容显示成图标,应如何设置?我曾把代码中“.Style = msoButtonCaption”改成“.Style = msoButtonIcon”,但再执行“Set .Picture = LoadPicture("D:\XXX.ico")”时提示“属性的使用无效”
代码不多,麻烦各位朋友给看看,谢谢!
Implements IDTExtensibility2
'Global object references
Public appHostApp As Excel.Application
Private WithEvents cbbButton As Office.CommandBarButton
Private Sub cbbButton_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
MsgBox ("Hello World!")
End Sub
Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
' 存储启动引用
Set appHostApp = Application
' 添加命令条
Set cbbButton = CreateBar()
End Sub
Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
RemoveToolbar
' 移除要关闭的引用
Set appHostApp = Nothing
Set cbbButton = Nothing
End Sub
Public Function CreateBar() As Office.CommandBarButton
' 指定命令条
Dim cbcMyBar As Office.CommandBar
Dim btnMyButton As Office.CommandBarButton
On Error GoTo CreateBar_Err
Set cbcMyBar = appHostApp.CommandBars.Add(Name:="GreetingBar")
' 指定命令条按钮
Set btnMyButton = cbcMyBar.Controls.Add(Type:=msoControlButton, _
Parameter:="Greetings")
With btnMyButton
.Style = msoButtonCaption
.BeginGroup = True
.Caption = "&Greetings"
.ToolTipText = "Display Hello World Message"
.Width = "24"
End With
' 显示并返回命令条
cbcMyBar.Visible = True
Set CreateBar = btnMyButton
Exit Function
CreateBar_Err:
MsgBox Err.Number & vbCrLf & Err.Description
End Function
Private Function RemoveToolbar()
appHostApp.CommandBars("GreetingBar").Delete
End Function
Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
End Sub
1.现在新建的工具栏只有一项,怎样创建更多?
2.如果我想把新建工具栏内容显示成图标,应如何设置?我曾把代码中“.Style = msoButtonCaption”改成“.Style = msoButtonIcon”,但再执行“Set .Picture = LoadPicture("D:\XXX.ico")”时提示“属性的使用无效”
代码不多,麻烦各位朋友给看看,谢谢!
Implements IDTExtensibility2
'Global object references
Public appHostApp As Excel.Application
Private WithEvents cbbButton As Office.CommandBarButton
Private Sub cbbButton_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
MsgBox ("Hello World!")
End Sub
Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
' 存储启动引用
Set appHostApp = Application
' 添加命令条
Set cbbButton = CreateBar()
End Sub
Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
RemoveToolbar
' 移除要关闭的引用
Set appHostApp = Nothing
Set cbbButton = Nothing
End Sub
Public Function CreateBar() As Office.CommandBarButton
' 指定命令条
Dim cbcMyBar As Office.CommandBar
Dim btnMyButton As Office.CommandBarButton
On Error GoTo CreateBar_Err
Set cbcMyBar = appHostApp.CommandBars.Add(Name:="GreetingBar")
' 指定命令条按钮
Set btnMyButton = cbcMyBar.Controls.Add(Type:=msoControlButton, _
Parameter:="Greetings")
With btnMyButton
.Style = msoButtonCaption
.BeginGroup = True
.Caption = "&Greetings"
.ToolTipText = "Display Hello World Message"
.Width = "24"
End With
' 显示并返回命令条
cbcMyBar.Visible = True
Set CreateBar = btnMyButton
Exit Function
CreateBar_Err:
MsgBox Err.Number & vbCrLf & Err.Description
End Function
Private Function RemoveToolbar()
appHostApp.CommandBars("GreetingBar").Delete
End Function
Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
End Sub
#4
学习
#5
继承了一个接口,那么即便某个方法下面没有处理代码,也要保证这个"接口"的完整性.
#6
还有一个问题,上述代码实现了一个工具栏中的一个按钮,但不知道怎样实现菜单?希望高手指教,谢谢!
#7
学习
#8
谢谢,学习了