Such a problem: there is an xml-file, inside which there is a table. One of the fields in the table is an image. It is not convenient to follow the "insert-image" path every time. Who knows the macro, which places in the corner of the cell the icon "+" on which we click and the explorer window appears to select a photo. ?

And one more problem in the topic: the same "+", but only it has to add a new line (with the given widths and heights of the cells).

I hope for your help.

    1 answer 1

    The procedure for opening a dialog to select files:

    Sub OpenPictureDialog() With Application.FileDialog(msoFileDialogOpen) .ButtonName = "Выбрать изображение" .Title = "Добавить выбранное изображение" ' Начальный каталог с изображениями .InitialFileName = "C:\Users\admin\Pictures\" .Filters.Clear ' Фильтр изображений, в данном случае только *.jpeg, *.jpg .Filters.Add "Файлы изображений", "*.jp*" If .Show <> -1 Then Exit Sub ActiveSheet.Pictures.Insert(.SelectedItems(1)).Select PS = Application.PathSeparator End With End Sub 

    If you need to insert a picture directly into the cell itself, then it is better to add another macro from here .

    The procedure for opening a form with input fields:

     Sub InsertRow() ' Показываем форму ввода ширины/высоты ячеек AddRow.Show End Sub 

    The main macro that calls previous procedures and draws a button:

     Sub AddButton() Dim btnX1, btnX2, btnY1, btnY2 As Integer Dim padding As Integer Dim r, rH, c, cW As Integer padding = 3 r = ActiveCell.row - 1 rH = 0 c = ActiveCell.Column - 1 cW = 0 For i = 1 To r rH = rH + Rows(i).Height Next i For i = 1 To c cW = cW + Columns(i).Width Next i ' Координаты кнопки в ячейке btnX1 = cW + padding btnY1 = rH + padding btnX2 = ActiveCell.Height - padding * 2 btnY2 = ActiveCell.Height - padding * 2 ' Добавляем кнопку в активную ячейку ActiveSheet.Buttons.Add(btnX1, btnY1, btnX2, btnY2).Select ' Добавляем выбранную картинку на страницу ' Selection.OnAction = "OpenPictureDialog" ' Вставляем новую строку под активной ячейкой ' Selection.OnAction = "InsertRow" Selection.Caption = "+" End Sub 

    Depending on the requirements, uncomment either Selection.OnAction = "OpenPictureDialog" or Selection.OnAction = "InsertRow"

    The input form itself:

    enter image description here

    Code for the OK button:

     Private Sub InsertButton_Click() If CellWidth.Text = "" Or CellHeight.Text = "" Then MsgBox ("Значение не указано!") End If Rows(ActiveCell.row + 1).Select Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove Selection.RowHeight = Val(CellHeight.Text) Selection.ColumnWidth = Val(CellWidth.Text) Close End Sub