通过Button Userform VBA插入PNG图像

时间:2017-11-09 17:45:55

标签: excel vba

我有一个带有按钮的用户窗体,它会提示用户上传图片,一切都很完美。但是,当我尝试以.png格式上传时,会显示错误消息Invalid Picture。我假设它不允许.png格式...有没有解决此问题?

Private Sub CommandButton1_Click()

    With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = False
        .ButtonName = "Submit"
        .Title = "Select an image file"
        .Filters.Add "Image", "*.gif; *.jpg; *.jpeg; *.png", 1
        If .Show = -1 Then
            ' file has been selected

            ' e.g. show path in textbox
            Me.TextBox1.Text = .SelectedItems(1)

            ' e.g. display preview image in an image control
            Me.Image1.PictureSizeMode = fmPictureSizeModeZoom
            Me.Image1.Picture = LoadPicture(.SelectedItems(1))
        Else
            ' user aborted the dialog

        End If
    End With

End Sub

0 个答案:

没有答案