vba生成没有工具栏的workbook

vba生成没有工具栏的workbook,第1张

End If

'-----------------------------------------------------------

'2. 合并单元格

nIndex = 2

strCaption = '合并单元格'

strParam = '合并单元格以及居中'

strCommand = '合并单元格'

nFaceId = 29

If zyi_Bar.Controls.Count <nIndex Then

AddComBarBtn strParam, strCaption, strCommand, nIndex, nFaceId

ElseIf zyi_Bar.Controls(nIndex).Caption <>strCaption Then

AddComBarBtn strParam, strCaption, strCommand, nIndex, nFaceId

End If

'-----------------------------------------------------------

'3. 居中

nIndex = 3

strCaption = '居中'

strParam = '水平垂直居中'

strCommand = '居中单元格'

nFaceId = 482

If zyi_Bar.Controls.Count <nIndex Then

AddComBarBtn strParam, strCaption, strCommand, nIndex, nFaceId

ElseIf zyi_Bar.Controls(nIndex).Caption <>strCaption Then

AddComBarBtn strParam, strCaption, strCommand, nIndex, nFaceId

End If

'-----------------------------------------------------------

'4. 货币

nIndex = 4

strCaption = '货币'

strParam = '货币'

strCommand = '货币'

nFaceId = 272

If zyi_Bar.Controls.Count <nIndex Then

AddComBarBtn strParam, strCaption, strCommand, nIndex, nFaceId

ElseIf zyi_Bar.Controls(nIndex).Caption <>strCaption Then

AddComBarBtn strParam, strCaption, strCommand, nIndex, nFaceId

End If

'-----------------------------------------------------------

'5. 将货币数字转换为大写

nIndex = 5

strCaption = '删除列'

strParam = '删除列'

'宏名称

strCommand = '删除列'

nFaceId = 1668

If zyi_Bar.Controls.Count <nIndex Then

AddComBarBtn strParam, strCaption, strCommand, nIndex, nFaceId

ElseIf zyi_Bar.Controls(nIndex).Caption <>strCaption Then

AddComBarBtn strParam, strCaption, strCommand, nIndex, nFaceId

End If

nIndex = nIndex + 1

While nIndex <zyi_Bar.Controls.Count

zyi_Bar.Controls(nIndex).Delete

Wend

'-----------------------------------------------------------

'6. 分割条

zyi_Bar.Controls(zyi_Bar.Controls.Count).BeginGroup = True

'-----------------------------------------------------------

'7. 将货币数字转换为大写

nIndex = 6

strCaption = '人民币'

strParam = '人民币由数字转换为大写'

'宏名称

strCommand = 'To大写人民币'

nFaceId = 384

If zyi_Bar.Controls.Count <nIndex Then

AddComBarBtn strParam, strCaption, strCommand, nIndex, nFaceId

ElseIf zyi_Bar.Controls(nIndex).Caption <>strCaption Then

AddComBarBtn strParam, strCaption, strCommand, nIndex, nFaceId

End If

nIndex = nIndex + 1

While nIndex <zyi_Bar.Controls.Count

zyi_Bar.Controls(nIndex).Delete

Wend

'-----------------------------------------------------------

'9. 分割条

zyi_Bar.Controls(zyi_Bar.Controls.Count).BeginGroup = True

100:

End Sub

'-------------------------------------------------------------------------------------------------------------

'向工具栏动态添加按钮

'-------------------------------------------------------------------------------------------------------------

Sub AddComBarBtn(strParam As String, strCaption As String, strCommand As String, nIndex As Integer, nFaceId As Integer)

'

Set zyi_ComBarBtn = zyi_Bar.Controls.Add( _

ID:=1, _

Parameter:=strParam, _

Before:=nIndex, _

Temporary:=True)

With zyi_ComBarBtn

.Caption = strCaption

.Visible = True

.OnAction = strCommand

.FaceId = nFaceId

End With

End Sub

通过以上两个函数,就可以实现自动添加工具栏及按钮。

剩下将在Workbook_Open函数里调用AddToolBar,即可实现文件打开就会显示工具栏。如果仅作为工具存放,则可以把该文件保存为模版文件,即xxx.xla。

Private Sub Workbook_Open()

' MsgBox '欢迎使用Excel', vbInformation + vbOKOnly, '增强工具'

Application.StatusBar = '欢迎使用增强工具:zyi'

'显示工具栏

AddToolBar

End Sub

到此,一个来工具栏的宏大功告成了。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报。

展开剩余内容

打开APP阅读全文并永久保存

5.添加宏到工具条

CATIA工具条是具有一定功能的图标按钮组合,一般停靠在用户窗口周围或浮动在界面上。用户可以通过工具条快捷调用特定 *** 作,使用起来比较方便。

CATIA提供了自定义工具条机制,可以把CATIA宏或VBA项目添加到指定模块的工具条中,供用户随时的调用。假设需要将前面讲到的创建正弦曲线的宏文件在创成式曲面设计(GSD)模块下添加工具条,其 *** 作步骤如下:

(1)打开“定制…”菜单

先把当前CATIA环境切换到创成式曲面设计(创建完成后的工具条在当前模块中出现),然后点击“工具->定制…”(或“工具->自定义…”,不同版本汉化时有差异),d出对话框如下图:

选择“命令”选项卡,在左侧列表“类别”中选择“宏”,此时右侧可见当前宏库中的宏文件。我们选择sincurve2.catvbs,在“显示属性…”中为此命令选择图标并设定快捷键。

选择“工具栏”选项卡,单击右侧“新建…”按钮,在d出的对话框中输入工具栏名称,如“正弦曲线”,则左侧列表中出现正弦曲线条目。

点击“添加命令…”按钮,在命令列表中选择sincurve2.catvbs, *** 作完成,在CATIA窗口中出现新工具条。点击此工具条,则系统开始执行sinecurve2.vbs,完成正弦曲线的创建。

在菜单栏上右击选择“自定义”,d出自定义对话框。

选择“命令”选项卡,在左侧一栏中找到“宏”并点击,这时候右面就出来“自定义菜单项”和“自定义按钮”两项,按住自定义按钮拖到菜单栏上就好了。

这时候“自定义”对话框先不要关,在刚刚按钮上右击,选择指定宏,把你写的宏选上就可以了~~

你是怎么不能实现呢?是给按钮设置宏的时候找不到名为CommandButton1_Click的宏?如果这样的话,你把private改为public试试~~

另外增加的这个按钮只是对你这台电脑的所有Excel都适用,换电脑了这个按钮就没了,貌似用xla也一样,不过可以设置快捷键,这个是放其他电脑也是可用的

我接触VBA也就一个月,所以上面只是按我的理解写的,最后一段不一定正确啊

你的这个宏是private的,要设置成public的啊,上面第六行说了啊

public Sub CommandButton1_Click()

MsgBox Sheets.Count

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11935688.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存