如何将图像以用户形式从图像框导出到单元格中(并在必要时将其清除)

时间:2019-07-05 07:43:43

标签: excel vba

我知道类似的问题很多,但是我已经差不多了,只是缺少一些额外的功能。

想法描述-

1:用户通过按下CommandButton通过Userform选择图像文件。图像填充在用户窗体中的图像框中,因此用户可以预览要放入的图像。

2:万一发生错误,用户可以擦除此文件并加载一个新文件(还有另一个用于擦除的CommnadButton)

3:通过按第三个按钮,图像将与其余插入的数据一起导出到活动工作表。

我现在所拥有的:

Sub ChangeImage()
With Application.FileDialog(msoFileDialogFilePicker)
    .AllowMultiSelect = False
    .ButtonName = "Submit"
    .Title = "Select an image file"
    .Filters.Clear
    .Filters.Add "JPG", "*.JPG"
    .Filters.Add "JPEG File Interchange Format", "*.JPEG"
    .Filters.Add "Graphics Interchange Format", "*.GIF"
    .Filters.Add "Portable Network Graphics", "*.PNG"
    .Filters.Add "Tag Image File Format", "*.TIFF"
    .Filters.Add "All Pictures", "*.*"

    If .Show = -1 Then
        Dim img As Object
        Set img = ActiveSheet.Pictures.Insert(.SelectedItems(1))

        'Scale image size
        'img.ShapeRange.ScaleWidth 0.75, msoFalse, msoScaleFromTopLeft
        'img.ShapeRange.ScaleHeight 0.75, msoFalse, msoScaleFromTopLeft

        'Position Image
        img.Left = 50
        img.Top = 50

        'Set image sizes in points (72 point per inch)
        img.Width = 150
        img.Height = 150
    Else
        MsgBox ("Cancelled.")
    End If
End with
End sub

这很有希望,但只会将图像放入工作表中。用户窗体中没有预览,也无法更改/删除它。有帮助吗?

0 个答案:

没有答案
相关问题