向Excel文档中嵌入VBA控件和UserForm并显示(3)

来源:未知 责任编辑:责任编辑 发表时间:2013-12-18 11:35 点击:

        objCommandButton.Caption = "Hello World" 
    End Sub 
End Class 
C#:

[csharp]
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Microsoft.Office.Tools.Ribbon; 
using VBE = Microsoft.Vbe.Interop; 
using Forms = Microsoft.Vbe.Interop.Forms; 
using Excel = Microsoft.Office.Interop.Excel; 
 
namespace ExcelAddIn16 

    public partial class Ribbon1 
    { 
        private Forms.CommandButton objCommandButton = null; 
        private void Ribbon1_Load(object sender, RibbonUIEventArgs e) 
        { 
 
        } 
 
        private void button1_Click(object sender, RibbonControlEventArgs e) 
        { 
            Excel.Application objApplication = Globals.ThisAddIn.Application; 
            Excel.Workbook objWorkbook = objApplication.ActiveWorkbook; 
            Excel.Worksheet objWorksheet = objWorkbook.ActiveSheet; 
            Excel.Shape objShape = objWorksheet.Shapes 
                .AddOLEObject("Forms.CommandButton.1"); 
            objShape.Name = "btn1"; 
            Excel.OLEObject objOLEObject = objWorksheet.OLEObjects("btn1"); 
            string strModuleString = string.Empty; 
            if (objOLEObject.Object is Forms.CommandButton) 
            { 
                objCommandButton =  
                    (Forms.CommandButton)objOLEObject.Object; 
                objCommandButton.Caption = "Embedded Button"; 
                objCommandButton.Click +=  

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

推荐热点

  • 浅析.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