【发布时间】:2020-10-29 10:09:19
【问题描述】:
我在 Excel 中使用 VBA 来制作用户窗体。我想在这个用户窗体中显示一个具有透明背景的 PNG 格式的图像。 最初我收到一条错误消息,因为 VBA 本身不支持 PNG 格式,所以我发现如果我引用 Microsoft Windows Image Acquisition Library v2.0 并使用以下代码,VBA 能够在 ImageControl 中显示 PNG 图像。
Sub ShowForm()
UserForm1.Image1.Picture = loadImg("C:\Temp\Logo.png")
UserForm1.Show
End Sub
Function loadImg(fileLocation As String) As IPictureDisp
Dim imgctrl As New WIA.ImageFile 'can handle more extensions than built in LoadPicture function
With imgctrl
.LoadFile fileLocation
Set loadImg = .fileData.Picture
End With
Set imgctrl = Nothing
End Function
我现在遇到的问题是图像显示但背景不透明。有人可以帮我解决这个问题吗? 我还有一个疑问是是否可以在 Excel 中嵌入图像,而不是像在 loadImg 函数中那样从路径调用它。
【问题讨论】:
-
只让图片背景和表格颜色一样不是更简单吗?为什么需要它是透明的?
-
谢谢,蒂姆!效果很好!
标签: vba background png transparency userform