动态生成多个VBE按钮控件并操作它们的属性
实现环境:Visual Studio 2010,Excel 2010, VSTO 4.0
[vb]
Imports Microsoft.Office.Tools.Ribbon
Imports VBE = Microsoft.Vbe.Interop
Imports Forms = Microsoft.Vbe.Interop.Forms
Public Class Ribbon1
Private Sub Ribbon1_Load(ByVal sender As System.Object, ByVal e As _
RibbonUIEventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles Button1.Click
Dim objApplication As Excel.Application = Globals.ThisAddIn.Application
Dim objWorkbook As Excel.Workbook = objApplication.ActiveWorkbook
Dim objWorksheet As Excel.Worksheet = objWorkbook.ActiveSheet
Dim iButtonNumber As Integer = CInt(EditBox1.Text)
Dim iHeight As Integer = 25
Dim iWeight As Integer = 125
Dim iTop As Integer = 0
Dim iLeft As Integer = 0
Dim objShape As Excel.Shape
Dim objOLEObject As Excel.OLEObject
Dim objCommandButtonControls As CommandButtonControls
For i As Integer = 1 To iButtonNumber Step 1
objShape = objWorksheet.Shapes.AddOLEObject _
("Forms.CommandButton.1", Left:=iLeft, _
Top:=iTop + iHeight * (i - 1), Height:=iHeight, Width:=iWeight)
objShape.Name = "btn" & CStr(i)
objOLEObject = objWorksheet.OLEObjects("btn" & CStr(i))
objCommandButtonControls = New CommandButtonControls _
(objShape.Name, "This is button" & objShape.Name)
objCommandButtonControls.objCommandButton = TryCast _
相关新闻>>
- 发表评论
-
- 最新评论 更多>>