excel VBA Userform中的图像控件不支持jpg文件?

5lhxktic  于 2023-06-07  发布在  其他
关注(0)|答案(1)|浏览(243)

当我尝试在UserForm中显示图像时,我收到以下消息:

'438' object doesn't support this property or method image control

它的工作方式是,在第一个文本框(img_path)我输入路径到img的目录,在第二个我输入文件的名称(NameImg)。这两个文本框的值被合并到图像控件(ImgControl)的图像路径中。

Private Sub Show_Click()
Dim show_img As String
Dim img As String
ing = NameImg.Value + ".jpg"

show_img = img_path.Text + img
ImgControl = LoadPicture(show_img)

End Sub

Private Sub Select_Click()
Dim diaFolder As FileDialog
    Dim path As String
    
    Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
    diaFolder.AllowMultiSelect = False
    diaFolder.Title = "Select a Directory"
    
    If diaFolder.Show = -1 Then
        path = diaFolder.SelectedItems(1)
        path = path + "\"
        img_path.Text = path
    End If
    
    Set diaFolder = Nothing
End Sub

JPG文件的路径是正确的,所以我不知道是什么问题...

ki0zmccv

ki0zmccv1#

正如@Tim威廉姆斯指出的那样,我忘记了这里的图片属性:ImgControl = LoadPicture(show_img)应该是

ImgControl.Picture = LoadPicture(show_img)

相关问题