Greetings to All.
I have some Issues in the below Macro.
My intention is to Copy/Insert the multiple Images in a folder that I select to the multiple sheets of a excel workbook.
The Macro should only have to insert the select images to the sheets.
The sheets are named as "Sheet1, Sheet2, Sheet3... etc..."
I want to insert 1st Image to Sheet1, 2nd Image to Sheet2, 3rd Image to Sheet3...............etc.
And Suppose if there are 20 Sheets in the workbook and I have 10 Images to insert it in Sheet1, Sheet2..........Sheet10, then I want to delete the remaining sheets(that is Sheet11, Sheet12.....Sheet20).
Also the Image should be fit in the range of I4 : S26
Currently I'm using the below Macro, But it is not working as per my need. All the selected images are beeing copied to the Active Sheet.
Could anyone write/modify the macro to the above said conditions.
Thanks in Advance.
Expand|Select|Wrap|Line Numbers
- Sub Insert_Picture ()
- Dim myPicture As Variant
- Dim myCell As Range
- Dim lLoop As Long
- Dim Sht As Worksheet
- Dim n As Integer
- On Error Resume Next
- myPicture = Application.GetOpenFilename _
- ("Pictures (*.gif; *.jpg; *.bmp; *.tif; *.png),*.gif; *.jpg; *.bmp; *.tif *.png", , "SELECT FILE(S) TO IMPORT", MultiSelect:=True)
- If VarType(myPicture) = vbBoolean Then
- MsgBox "NO FILES SELECTED"
- Else
- n = 1
- If IsArray(myPicture) Then
- For lLoop = LBound(myPicture) To UBound(myPicture)
- Sheets("Sheet(n)").Select
- With ActiveSheet
- Set myCell = .Range("I4:S26")
- .Pictures.Insert(myPicture(lLoop)).Select
- With myCell
- Selection.Top = .Top
- Selection.Left = .Left
- Selection.Width = .Width
- Selection.Height = .Height
- Selection.Placement = xlMoveAndSize ' move and size with cells
- End With
- End With
- n = n + 1
- Next lLoop
- End If
- MsgBox "Copy Completed"
- End If
- End Sub