是否可以使用 base64 编码字符串作为命令栏按钮的图像.vba 中的图片属性



我在 32 位版本的 Access 中使用 mscomctl.ocx,但在转换为 64 位 Office 365 版本的 Access 时遇到图像列表资源问题。

32位版本我们正在使用此代码(带有图像列表(:

Set cbItem = cmdBar.Controls.Add(1)
With cbItem
.Caption = "Refresh"
.OnAction = "=fuPub_ExRefresh()"
.Picture = imgListComBar.ListImages("Refresh").Picture
.enabled = True
End With

在 64 位中,是否可以使用这样的东西......

Set cbItem = cmdBar.Controls.Add(1)
With cbItem
.Caption = "Refresh"
.OnAction = "=fuPub_ExRefresh()"
.Picture = ...some base64 string/object ??
.enabled = True
End With

CommandBarButton.Picture 属性允许设置一个表示 CommandBarButton 对象图像的IPictureDisp对象。

Sub ChangeButtonImage() 
Dim picPicture As IPictureDisp 
Dim picMask As IPictureDisp 
Set picPicture = stdole.StdFunctions.LoadPicture( _ 
"c:imagespicture.bmp") 
Set picMask = stdole.StdFunctions.LoadPicture( _ 
"c:imagesmask.bmp") 
'Reference the first button on the first command bar 
'using a With...End With block. 
With Application.CommandBars.FindControl(msoControlButton) 
'Change the button image. 
.Picture = picPicture 
'Use the second image to define the area of the 
'button that should be transparent. 
.Mask = picMask 
End With 
End Sub

您可以尝试从 base64 字符串还原IPictureDisp接口。有关详细信息,请参阅在 Office 中使用存储在 CustomXMLPart 中的 base64 数据作为图像:

Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Private Declare Function CreateStreamOnHGlobal Lib "ole32.dll" (ByRef hGlobal As Any,     ByVal fDeleteOnResume As Long, ByRef ppstr As Any) As Long
Private Declare Function OleLoadPicture Lib "olepro32.dll" (ByVal lpStream As IUnknown, ByVal lSize As Long, ByVal fRunMode As Long, ByRef riid As GUID, ByRef lplpObj As Any) As Long
Private Declare Function CLSIDFromString Lib "ole32.dll" (ByVal lpsz As Long, ByRef pclsid As GUID) As Long
Private Const SIPICTURE As String = "{7BF80980-BF32-101A-8BBB-00AA00300CAB}"
Public Function PictureFromArray(ByRef b() As Byte) As IPicture
On Error GoTo errorhandler
Dim istrm As IUnknown
Dim tGuid As GUID
If Not CreateStreamOnHGlobal(b(LBound(b)), False, istrm) Then
CLSIDFromString StrPtr(SIPICTURE), tGuid
OleLoadPicture istrm, UBound(b) - LBound(b) + 1, False, tGuid, PictureFromArray
End If
Set istrm = Nothing
Exit Function
errorhandler:
Debug.Print "Could not convert to IPicture!"
End Function

最新更新