automatically selecting all files(.jpg) in a folder and copying to excel sheet without using getopen file

paran

New Member
Joined
Aug 23, 2021
Messages
32
Office Version
  1. 365
Platform
  1. Windows
having container id as sheet name from sheet 15 to last sheet, need a macro to search for a file with sheet name(ABCD1234567) as the file name in mentioned path ( c:\photos), upon matching it should copy all the jpg photos from that file (ABCD1234567) and paste in that sheet name ( sheet name and file name will be same ) and loop will be there till last sheet without using getopenfile and will doing automatically

please help out bro
 
Or the real picture:

Enlarge the row.heights in your sheets before you run this macro.

VBA Code:
Sub jec()
 Dim it As Variant, c00 As String, objFolder As String, i As Long, x As Long
 c00 = "C:\Users\XXXX\Pictures\"
  
 With CreateObject("scripting.filesystemobject")
    For i = 15 To Sheets.Count
       objFolder = c00 & Sheets(i).Name
        If .FolderExists(objFolder) Then
           For Each it In .getfolder(objFolder).Files
              x = x + 1
              Sheets(i).Shapes.AddPicture it, False, True, Columns(1).Left, Rows(x + 17).Top, Columns(1).Width, Rows(x + 17).Height
           Next
        End If
       x = 0
    Next
 End With
End Sub
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
thanks bro for your effort,but only links are pasted ,we need real jpg image to be pasted in a17 to 5 column and then next row till 5 column ...so on till last jpg image image should of same size
Note, I changed the i =2 to i = 15 in the loop. I tested with 2, forgot to change
 
Upvote 0
The last code I posted, does paste the real picture
 
Upvote 0
Note, I changed the i =2 to i = 15 in the loop. I tested with 2, forgot to change
sorry for the late reply, thanks sir it worked fine, but i want the real image as shown in the image below with same size and small gap between the photos not the link
the pics will be from a17 to 5 column then next row till 5 column and so on .....
thanks for your kind effort once again sir ,awaiting your reply
 

Attachments

  • Screenshot 2021-12-30 200033_11zon.jpg
    Screenshot 2021-12-30 200033_11zon.jpg
    43.3 KB · Views: 7
Upvote 0
sorry for the late reply, thanks sir it worked fine, but i want the real image as shown in the image below with same size and small gap between the photos not the link
the pics will be from a17 to 5 column then next row till 5 column and so on .....
thanks for your kind effort once again sir ,awaiting your reply
yes it pasting the real pic ,but in one column only ,we want as said earlier message it should paste horzontally 5 column the next row and so on
since the column and row set to the estimates above so we can change ,sir can we do it in one blank sheet with column and row increasing the height and width and then again pasting to the required sheet...
90% job is over ,please guide us......
 
Upvote 0
Yes but you only keep changing your explanation after I post code. Last try:
You can change the picture sizes yourself if they are not as desired.

Let me know if this works!

VBA Code:
Sub jec()
 Dim it As Variant, c00 As String, objFolder As String
 Dim i As Long, x As Long, y As Long, q As Long
 
 c00 = "C:\Users\XXX\Pictures\"
 
 With CreateObject("scripting.filesystemobject")
    For i = 15 To Sheets.Count
       objFolder = c00 & Sheets(i).Name
        If .FolderExists(objFolder) Then
           For Each it In .getfolder(objFolder).Files
              x = x + 1
              y = (x - 1) Mod 5 + 1
              q = (x - 1) \ 5 + 1
              Sheets(i).Shapes.AddPicture it, False, True, (y - 1) * 140 + (10 * y), q * 255 + (10 * q), 140, 255
           Next
        End If
       x = 0
    Next
 End With
End Sub
 
Last edited:
Upvote 0
Solution
Yes but you only keep changing your explanation after I post code. Last try:
You can change the picture sizes yourself if they are not as desired.

Let me know if this works!

VBA Code:
Sub jec()
 Dim it As Variant, c00 As String, objFolder As String
 Dim i As Long, x As Long, y As Long, q As Long
 
 c00 = "C:\Users\XXX\Pictures\"
 
 With CreateObject("scripting.filesystemobject")
    For i = 15 To Sheets.Count
       objFolder = c00 & Sheets(i).Name
        If .FolderExists(objFolder) Then
           For Each it In .getfolder(objFolder).Files
              x = x + 1
              y = (x - 1) Mod 5 + 1
              q = (x - 1) \ 5 + 1
              Sheets(i).Shapes.AddPicture it, False, True, (y - 1) * 140 + (10 * y), q * 255 + (10 * q), 140, 255
           Next
        End If
       x = 0
    Next
 End With
End Sub
thanks sir,u r genius,
sorry for change,since i coulkd not explain fully
thanks a lot
 
Upvote 0
sir good morning
sorry to disturb u again, want an last code in continuation to above code ,to delete the file after copying and the file not found should pop up at last

had tryied wit " kill objfolder" but showing error 53 path not found

please ....
 
Upvote 0
Try:

VBA Code:
Kill It
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,377
Members
448,955
Latest member
BatCoder

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top