假设所有需要显示的图片都但在F:\图库\文件夹中,Excel中有一表中输入了这些文件名(不含扩展名),要求:点击工作表中文件名就显示图片
1.插入image1控件
2.Alt+F11,将程序粘贴到本工作表模块中
Private
Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim strX As String
strX = "F:\图库\" & Selection.Value & ".jpg"
If Dir(strX) = "" Then
Image1.Picture = LoadPicture
Exit Sub
Else
Image1.Picture = LoadPicture(strX)
End If
End Sub
Private Sub CommandButton1_Click()
Image1.Picture = LoadPicture("c:\temp\1.jpg")
End Sub