微信公众号 【EXCEL880】 QQ群【341401932】
课程咨询 加我微信EXCEL880B 试学网址http://v.excel880.com
课程咨询 加我微信EXCEL880B 试学网址http://v.excel880.com
代码运行结果:
代码截图:
![VBA案例精选 快速填充编号](https://p6-tt.byteimg.com/origin/pgc-image/8bce1591f4ae4ebdaf3b2aebca857323.png?from=pc)
代码文本:
Public Sub 快速填充编号()
Dim myCommandBar As CommandBar
Dim myCommandBarCnt As CommandBarControl
Dim i As Long
Cells.Clear '清除所有单元格
For Each myShape In Worksheets(1).Shapes
If myShape.Name <> "myButton" Then
myShape.Delete '删除名字不为myButton的图形对象
End If
Next
On Error Resume Next
Application.CommandBars("FaceID").Delete
On Error GoTo 0
'创建一个临时的自定义工具栏FaceID
Set myCommandBar = Application.CommandBars.Add(Name:="FaceID")
Set myCommandBarCnt = myCommandBar.Controls.Add(Type:=1)
For i = 1 To 300
myCommandBarCnt.FaceId = i
myCommandBarCnt.CopyFace '复制命令按钮的Icon
With Worksheets(1)
.Paste '将复制的命令按钮Icon粘贴到工作表中
.Shapes(.Shapes.Count).Top = .Cells(i, 2).Top
.Shapes(.Shapes.Count).Left = .Cells(i, 2).Left
.Cells(i, 1).Value = i
End With
Next i
myCommandBar.Delete '删除临时的自定义工具栏FaceID
Set myCommandBarCnt = Nothing
End Sub
VBA编辑神器放送
VBA编程懒人神器推荐 VBA代码助手 可以极大提高编程速度,降低编程门槛欢迎使用
VBA密码破解 VBA代码对齐 VBA代码混淆保护加密 代码库输入提示 VBA模块隐藏
下载链接:http://excel880.com/blog/archives/11297