选择/上传图像到Userform

时间:2016-10-05 17:51:36

标签: macros userform

我正在创建一个包含图像框的用户表单。它具有在用户点击框时浏览文件的功能。理想情况下,我希望用户能够上传图片而无需导航到属性。我尝试使用ImageBox.Picture = LoadPicture(PicPath)将文件上传到图像框,但是我收到了424错误。任何有关这方面的帮助将不胜感激。这就是我到目前为止所做的:

Private Sub Screenshot_Click()

Dim fd As FileDialog
Dim PicPath As String

Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = False
If .Show = -1 Then
PicPath = .SelectedItems(1)
ImageBox.Picture = LoadPicture(PicPath)
Else: Exit Sub
End If
End With

End Sub

1 个答案:

答案 0 :(得分:0)

信用到期的信用:感谢vbaexpress论坛上的 ccollins48

Private Sub Screenshot_Click()

Dim PictFileName As String
PictFileName = Application.GetOpenFilename
PicPath = PictFileName

If Len(Dir(PicPath)) = 0 Then
MsgBox PicPath & "Error"
Else
Me.Screenshot.Picture = LoadPicture(PicPath)
Me.Repaint
End If
End Sub

将图片格式化为3-fmPictureSizeModeZoom