muhammad susanto
Well-known Member
- Joined
- Jan 8, 2013
- Messages
- 2,089
- Office Version
- 365
- 2021
- Platform
- Windows
hi expert....
this code work properly only for 3 pictures to inserted into 3 cells, but i want to modify how this code below work in n pictures (multiple pictures) then inserted only in cell H10 for each sheet..
expected result :
example :
1.jpg----inserted in SheetA--cell H10
2.jpg----inserted in SheetB--cell H10
3.jpg----inserted in SheetC--cell H10
100.jpg---inserted in SheetXX--cell H10
etc...
.sst
this code work properly only for 3 pictures to inserted into 3 cells, but i want to modify how this code below work in n pictures (multiple pictures) then inserted only in cell H10 for each sheet..
Code:
Sub InsertPic()
Dim I As Long
Dim xPath As String
Dim xShape As Shape
Dim xRg As Range
Dim xFiles
Dim j As Long
Dim a As Range
xPath = "L:\test\"
xFiles = Array("1.jpg", "2.jpg", "3.jpg")
If Dir(xPath & "*.jpg") = "" Then
MsgBox "Picture file was not found in path!", vbInformation, "test"
Exit Sub
End If
For I = 1 To ActiveWorkbook.Sheets.Count
Set xRg = Sheets(I).Range("B10:C10,D10:E10,f10:g10")
For j = 1 To xRg.Areas.Count
Set a = xRg.Areas(j)
Set xShape = Sheets(I).Shapes.AddPicture(xPath & xFiles(j - 1), True, True, a.Left, a.Top, a.Width, a.Height)
Next
Next
End Sub
expected result :
example :
1.jpg----inserted in SheetA--cell H10
2.jpg----inserted in SheetB--cell H10
3.jpg----inserted in SheetC--cell H10
100.jpg---inserted in SheetXX--cell H10
etc...
.sst
Last edited: