如果想要提取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
效果:

最後一頁:

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