1

たくさんのテキストボックスを持つユーザーフォームがあります。エンド ユーザーがテスト データをフォームに入力し、[送信] ボタンをクリックすると、この情報が Excel シートに保存されます。ユーザーがコンピューターからフォームに画像を入力できるようにする方法を考えています。

要件: エンド ユーザーが自分のコンピューターから画像を選択し、フォームの [送信] をクリックして Excel シートに挿入できること。

Private Sub CommandButton3_Click()
    Dim image As FileDialog 
    Set image = Application.FileDialog(msoFileDialogFilePicker) 
    Dim vrtSelectedPicture As Variant 
    With image 
        If .Show = -1 Then
        For Each vrtSelectedPicture In .SelectedItems                 
            'Show path in textbox
            TextBox71.Text = .SelectedItems(1)      
        Next vrtSelectedPicture
        'The user pressed Cancel.
        Else
        End If
    End With
    'Set the object variable to Nothing
    Set image = Nothing
End Sub
4

1 に答える 1

2

確かに、ここに についてのアイデアを与えるサンプル コードがありますFileDialog

Private Sub CommandButton1_Click()

    With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = False
        .ButtonName = "Submit"
        .Title = "Select an image file"
        .Filters.Add "Image", "*.gif; *.jpg; *.jpeg", 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
于 2013-08-04T18:15:49.417 に答える