VBA 图片控件载入图片出错(没有图片时)?

2024-10-29 18:11:26
推荐回答(1个)
回答(1):

写一个判断文件是否存在的函数
Function ExistsFile_UseFso(strPath As String) As Boolean

Dim fso

Set fso = CreateObject("Scripting.FileSystemObject")

ExistsFile_UseFso = fso.FileExists(strPath)

Set fso = Nothing

End Function
然后在你loadpicture之前判断一下:
if ExistsFile_UseFso("E:\相片\李艳.JPG") then
Image1.Picture = LoadPicture("E:\相片\李艳.JPG")
end if