英文:
Image control in VBA Userform doesn't support jpg file?
问题
在尝试在用户窗体中显示图像时,我收到了以下消息:
'438' 对象不支持此属性或方法图像控件
它的工作方式是,在第一个文本框(img_path)中输入图像目录的路径,在第二个文本框中输入文件的名称(NameImg)。这两个文本框的值被组合成图像控件(ImgControl)的路径。
Private Sub Show_Click()
Dim show_img As String
Dim img As String
img = NameImg.Value & ".jpg"
show_img = img_path.Text & img
ImgControl.Picture = 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文件的路径是正确的,所以我不知道问题出在哪里...
英文:
While trying to display image in UserForm I get this message:
'438' object doesn't support this property or method image control
The way it works is that in 1st textbox(img_path) I input path to img's directory, in 2nd one I input file's name(NameImg). Both textboxes' values are combined into path to the image for image control (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
The path to jpg file is correct so I don't know what's the problem...
答案1
得分: 0
ImgControl.Picture = LoadPicture(show_img)
英文:
As @Tim Williams pointed out I forgot about Picture property here:
ImgControl = LoadPicture(show_img)
it should be
ImgControl.Picture = LoadPicture(show_img)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论