显示列表框选择的图像

时间:2018-10-30 13:43:47

标签: excel vba

我正在尝试为每个列表框项目显示一个图像。

“ boss.jpg”位于名为“ VBA”的桌面文件夹中,在我可以正常显示“ boss.jpg”图像之前,我还没有向该文件夹添加其他列表框项目或图片。

Option Explicit

Private Sub Image1_BeforeDragOver(ByVal Cancel As MSForms.ReturnBoolean, _
  ByVal Data As MSForms.DataObject, ByVal X As Single, ByVal Y As Single, _
  ByVal DragState As MSForms.fmDragState, ByVal Effect As MSForms.ReturnEffect, _
  ByVal Shift As Integer)

    Dim picPath As String
    Dim strPath As String

    strPath = "C:\Users\Jason\Desktop\VBA"

    picPath = strPath & "Boss\" & Image1.Value & ".jpg"

    imgPictures.Picture = LoadPicture(picPath)

End Sub

Private Sub UserForm_Initialize()

    ListBox1.AddItem "boss"
    ListBox1.AddItem "Keep off grass"

End Sub

0 个答案:

没有答案