我正在用Excel中的VBA来制作一个UserForm。我想在这个UserForm中显示一个透明的背景图像是在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函数中那样从路径调用它。
发布于 2021-03-05 01:24:44
我知道已经有一段时间了,但现在我们开始吧:将你的图像(例如,在Photoshop中)保存在".gif“中。然后,在Excel / userform中插入图像。在窗口中,选择“所有文件”,"image.gif“将会出现。与".png“相比,它只是稍微失去了一些质量。
https://stackoverflow.com/questions/62804265
复制相似问题