i am not able to insert pictures via names in merged cells and most of my pics are not fit properly.

also my inserted images not showing in another system please help me. plzz
Hello Vipinpanchal2008

Thanks for reaching out and posting your query. You are unable to insert images using names. Besides, you cannot fit the inserted images within merged cells.

I am delighted to inform you that I have developed an Excel VBA sub-procedure to fulfil your requirements. Unlike the previous solution in another thread, this time, I have defined the cellAddress variable as ranges instead of cells.

I am doing these only for four images. You can only define the desired amount of merged ranges in the code and Run.

Excel VBA Sub-procedure:
Code:
Sub InsertAnFitImagesInMergedCells()

    Dim cellAddresses As Variant
    Dim cellAddress As Variant
    Dim imgFile As Variant
    Dim pic As Picture
    Dim i As Long
    Dim cell As Range
    Dim mergedWidth As Double
    Dim mergedHeight As Double

    cellAddresses = Array("B5:L29", "B31:L55", "B64:L86", "B88:L112")

    With Application.FileDialog(msoFileDialogFilePicker)
        .Title = "Select Image Files"
        .Filters.Add "Image Files", "*.jpg; *.jpeg; *.png; *.gif; *.bmp", 1
        .AllowMultiSelect = True

        If .Show = -1 Then
            For i = 1 To .SelectedItems.Count
                cellAddress = cellAddresses(i - 1)

                Set cell = ThisWorkbook.Sheets("Snaps").Range(cellAddress)

                mergedWidth = cell.Width
                mergedHeight = cell.Height

                Set pic = cell.Parent.Pictures.Insert(.SelectedItems(i))

                pic.ShapeRange.LockAspectRatio = msoFalse
                pic.Width = mergedWidth
                pic.Height = mergedHeight

                pic.Left = cell.Left
                pic.Top = cell.Top
            Next i
        End If
    End With

End Sub

OUTPUT:
Vipinpanchal2008 (Solved).png

I am also attaching the solution workbook to help you understand better. Stay Blessed.

Regards
Lutfor Rahman Shimanto
 

Attachments

  • Vipinpanchal2008 (SOLVED).xlsm
    120.8 KB · Views: 1

Online statistics

Members online
0
Guests online
11
Total visitors
11

Forum statistics

Threads
303
Messages
1,331
Members
550
Latest member
JasonRip
Top