动态生成多个VBE按钮控件并操作它们的属性

来源:未知 责任编辑:责任编辑 发表时间:2013-12-22 14:55 点击:

实现环境: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 _ 

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • 浅析.NET下XML数据访问新机制
  • asp.net 面试+笔试题目第1/2页
  • C# 邮件地址是否合法的验证
  • C#高级编程:数据库连接[1]
  • asp.net 设置GridView的选中行的实现代码
  • 经典C++程序1
  • IIS 自动回收导致后台定时器失效的问题解决
  • ASP.NET GridView列表代码示例
  • 微软ASP.NET站点部署指南(3):使用Web.Config文件的Transforma
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1