求助:VBA中模块和对象
本人是个VBA新手,自己编辑了一个Excel宏代码,要求记录当前工具栏的数量和名称:
Public Sub RcdOldBar()'记录文档已经打开的工具栏,并进行隐藏Dim OldBarNoDim OldBarName() OldBarNo = 0 ReDim OldBarName(OldBarNo) For Each CommandBar In CommandBars '检测是否有打开的工具栏 If CommandBar.Type = msoBarTypeNormal Then '逐个检查文件工具栏 If CommandBar.Visible = True Then '是否是显示的工具栏 OldBarNo = OldBarNo + 1 '是,工具栏数量加1 ReDim Preserve OldBarName(OldBarNo) '改变数组大小 OldBarName(OldBarNo) = CommandBar.Name '记录工具栏名称 Application.CommandBars(OldBarName(OldBarNo)).Visible = False '隐藏工具栏显示 End If End If Next CommandBarEnd Sub
For Each CommandBar In Excel.Application.CommandBars