vba读取excel文件内容(让vba引用单元格里的值方法)

如果想要提取Excel界面的某个图标,可以使用VBA的CommandBars对象将其提取出来:

Application.CommandBars.Controls.intFaceId

Application.CommandBars.Controls.CopyFace

intFaceId从1-18028

Option Explicit

Sub 获取Excel中的所有内置控件的FaceId和图像()
    Dim cbr As CommandBar, ctl As CommandBarButton
    Dim intCol As Integer, intRow As Integer
    Dim intFaceId As Integer
    If Application.WorksheetFunction.CountA(Cells) <> 0 Then
        MsgBox "活动工作表中包含数据,请选择一个空工作表!"
        Exit Sub
    End If
    On Error GoTo errTrap '错误捕捉
    Application.ScreenUpdating = False
    Set cbr = Application.CommandBars.Add(MenuBar:=False, Temporary:=True)
    Set ctl = cbr.Controls.Add(Type:=msoControlButton, Temporary:=True)
    intRow = 1
    Do
        For intCol = 1 To 8
            intFaceId = intFaceId + 1
            Application.StatusBar = "FaceID=" & intFaceId  ' 状态栏提示一下
            ctl.FaceId = intFaceId
            ctl.CopyFace '复制图标图像,如果复制的是不可见图像,会出现编号为1004的错误
            ActiveSheet.Paste Cells(intRow, intCol + 1) '粘贴图标图像
            Cells(intRow, intCol).Value = intFaceId
        Next intCol
        intRow = intRow + 1
    Loop
errTrap: '错误处理
    If Err.Number = 1004 Then Resume Next
    Application.StatusBar = False
    cbr.Delete
    Application.ScreenUpdating = True
End Sub

效果:

VBA|获取Excel中的所有内置控件的FaceId和图像VBA|获取Excel中的所有内置控件的FaceId和图像

最后一页:

VBA|获取Excel中的所有内置控件的FaceId和图像VBA|获取Excel中的所有内置控件的FaceId和图像

-End-

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,请发送邮件至624739273@qq.com举报,一经查实,本站将立刻删除。
Like (0)
柳的头像

相关推荐

发表回复

Please Login to Comment
微信
微信
SHARE
TOP
要想花得少,就用购宝。话费电费9折起,官方公众号:购宝