Hello!

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