首页 > 解决方案 > Display image for a Listbox selection

问题描述

I am trying to display an image for each listbox item if it is selected.

The 'boss.jpg' is located in a desktop folder called 'VBA', I have yet to add additonal listbox items or pictures to the folder until I can get the 'boss.jpg' image to display properly.

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

标签: excelvba

解决方案


推荐阅读