jkomorowski
New Member
- Joined
- Jun 26, 2008
- Messages
- 12
Hi, I am fairly new to macro writing and am having trouble converting an old macro that I had working for 2003, but that wont work for 2007. I have searched the internet and found numerous other postings on replacing application.filesearch, but I can't seem to get any of them working for me.
I am trying to search a folder that is selected by the user for all .jpg files, and then place all those pictures onto a certain spreadsheet within the excel file. It also formats the pictures. Following is the code:
Any and all help would be greatly appreciated.
Thanks, Jason
I am trying to search a folder that is selected by the user for all .jpg files, and then place all those pictures onto a certain spreadsheet within the excel file. It also formats the pictures. Following is the code:
Code:
Private Sub BatchProcessThumb2x3()
Msg = "Select a file containing the photos you want to insert."
Directory = GetDirectory(Msg)
If Directory = "" Then Exit Sub
If Right(Directory, 1) <> "\" Then Directory = Directory & "\"
On Error Resume Next
With Application.FileSearch
.NewSearch
.LookIn = Directory
.Filename = "*.jpg"
.SearchSubFolders = False
.Execute
' Select begining range
Worksheets("Thumbnail (2x3)").Select
Range("B4").Select
' Loop through all files and process them
For i = 1 To .FoundFiles.Count
Application.StatusBar = "Processing " & .FoundFiles(i)
' Import and insert the photo
ActiveSheet.Pictures.Insert(.FoundFiles(i)).Select
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Width = 225#
If Int(i / 2) - (i / 2) <> 0 Then _
ColOff = 3 Else ColOff = -3
If Int(i / 2) - (i / 2) <> 0 Then _
RowOff = 0 Else RowOff = 4
ActiveCell.Offset(RowOff, ColOff).Select
Next i
Application.StatusBar = False
End With
End Sub
Any and all help would be greatly appreciated.
Thanks, Jason