用VBA动态向word添加命令按钮并指定按钮事件 |
利用VBA也可以生成宏代码 |
作者:未知 文章来源:Microsoft 点击数: 更新时间:2013-3-24 10:45:49  |
使用VBA动态向文档中添加控件的方法,查看了很多,还是觉得微软自己的示例最好用,粘贴如下:
Sub Test()
'Add a command button to a new document Dim doc As Word.Document Dim shp As Word.InlineShape Set doc = Documents.Add
Set shp = doc.Content.InlineShapes.AddOLEControl(ClassType:="Forms.CommandButton.1") shp.OLEFormat.Object.Caption = "Click Here"
'Add a procedure for the click event of the inlineshape '**Note: The click event resides in the This Document module Dim sCode As String sCode = "Private Sub " & shp.OLEFormat.Object.Name & "_Click()" & vbCrLf & _ " MsgBox ""You Clicked the CommandButton""" & vbCrLf & _ "End Sub" doc.VBProject.VBComponents("ThisDocument").CodeModule.AddFromString sCode
End Sub
点此访问原文页面。
{$MY_AD_Squar_article_left} |
文章录入:admin 责任编辑:admin |
|
上一篇文章: 为Word2003宏添加VBA项目的数字证书签名 下一篇文章: VB6.0封装Excel2007功能区菜单 ----Ribbon CustomUI 放在资源文件 |
【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |