讓vba引用單元格里的值方法「vba讀取excel文件內容」

如果想要提取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和圖像

-End-

原創文章,作者:投稿專員,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/273008.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
投稿專員的頭像投稿專員
上一篇 2024-12-17 14:03
下一篇 2024-12-17 14:03

相關推薦

發表回復

登錄後才能評論