![]() |
Inserting all pictures from a certain file folder
I know how insert pictures when i know the exact file name, and i learned how
to have the computer ask which file i want to insert, but how would someone insert all the pictures from a certain file folder? |
Inserting all pictures from a certain file folder
That'll put all the pictures in one location.
Maybe... Option Explicit Sub Macro() Dim strFolder As String Dim strFile As String Dim YourPic As Picture Dim DestCell As Range Set DestCell = ActiveSheet.Range("C3") strFolder = "c:\temp\" strFile = Dir(strFolder & "*.jpg", vbNormal) Do While strFile < "" With DestCell Set YourPic = .Parent.Pictures.Insert(strFolder & strFile) YourPic.Top = .Top YourPic.Width = .Width YourPic.Height = .Height YourPic.Left = .Left End With Set DestCell = DestCell.Offset(1, 0) strFile = Dir Loop End Sub Jacob Skaria wrote: Try the below macro. Change the folder name to suit your requirement..You will neeed to adjust the Range to a variable to suit... Sub Macro() Dim strFolder As String Dim strFile As String Dim YourPic As Picture strFolder = "c:\temp\" strFile = Dir(strFolder & "*.jpg", vbNormal) Do While strFile < "" With ActiveSheet.Range("C3") Set YourPic = .Parent.Pictures.Insert(strFolder & strFile) YourPic.Top = .Top YourPic.Width = .Width YourPic.Height = .Height YourPic.Left = .Left End With strFile = Dir Loop End Sub If this post helps click Yes --------------- Jacob Skaria "ironhydroxide" wrote: I know how insert pictures when i know the exact file name, and i learned how to have the computer ask which file i want to insert, but how would someone insert all the pictures from a certain file folder? -- Dave Peterson |
Inserting all pictures from a certain file folder
Dave, thanks for pointing that out.
The code inbetween the loop is something which the OP already have. I have mentioned in my post to adjust the range to suit the requirement. If this post helps click Yes --------------- Jacob Skaria "Dave Peterson" wrote: That'll put all the pictures in one location. Maybe... Option Explicit Sub Macro() Dim strFolder As String Dim strFile As String Dim YourPic As Picture Dim DestCell As Range Set DestCell = ActiveSheet.Range("C3") strFolder = "c:\temp\" strFile = Dir(strFolder & "*.jpg", vbNormal) Do While strFile < "" With DestCell Set YourPic = .Parent.Pictures.Insert(strFolder & strFile) YourPic.Top = .Top YourPic.Width = .Width YourPic.Height = .Height YourPic.Left = .Left End With Set DestCell = DestCell.Offset(1, 0) strFile = Dir Loop End Sub Jacob Skaria wrote: Try the below macro. Change the folder name to suit your requirement..You will neeed to adjust the Range to a variable to suit... Sub Macro() Dim strFolder As String Dim strFile As String Dim YourPic As Picture strFolder = "c:\temp\" strFile = Dir(strFolder & "*.jpg", vbNormal) Do While strFile < "" With ActiveSheet.Range("C3") Set YourPic = .Parent.Pictures.Insert(strFolder & strFile) YourPic.Top = .Top YourPic.Width = .Width YourPic.Height = .Height YourPic.Left = .Left End With strFile = Dir Loop End Sub If this post helps click Yes --------------- Jacob Skaria "ironhydroxide" wrote: I know how insert pictures when i know the exact file name, and i learned how to have the computer ask which file i want to insert, but how would someone insert all the pictures from a certain file folder? -- Dave Peterson |
All times are GMT +1. The time now is 10:13 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com