Hi All,
Im a newbie with VBA - just finding the code online i need for small projects. Ive found some code to import photos to a sheet based on cell values, but i need it to start inserting in to cell A2 not A10.
Also how can i get the photo to centre in the cell?
Any help is much appreciated.
Chris
Im a newbie with VBA - just finding the code online i need for small projects. Ive found some code to import photos to a sheet based on cell values, but i need it to start inserting in to cell A2 not A10.
Also how can i get the photo to centre in the cell?
Any help is much appreciated.
Chris
Code:
Sub IMPORTPHOTOS()
Dim mainWorkBook As Workbook
Set mainWorkBook = ActiveWorkbook
Sheets("QUOTESHEET").Activate
Folderpath = "C:\PHOTOS"
Set fso = CreateObject("Scripting.FileSystemObject")
NoOfFiles = fso.GetFolder(Folderpath).Files.Count
Set listfiles = fso.GetFolder(Folderpath).Files
For Each fls In listfiles
strCompFilePath = Folderpath & "" & Trim(fls.Name)
If strCompFilePath <> "" Then
If (InStr(1, strCompFilePath, "jpg", vbTextCompare) > 1 _
Or InStr(1, strCompFilePath, "jpeg", vbTextCompare) > 1 _
Or InStr(1, strCompFilePath, "png", vbTextCompare) > 1) Then
counter = counter + 1
Sheets("QUOTESHEET").Range("A1" & counter).Value = fls.Name
Sheets("QUOTESHEET").Range("A1" & counter).ColumnWidth = 12
Sheets("QUOTESHEET").Range("B1" & counter).RowHeight = 76
Sheets("QUOTESHEET").Range("B1" & counter).Activate
Call insert(strCompFilePath, counter)
Sheets("QUOTESHEET").Activate
End If
End If
Next
mainWorkBook.Save
End Sub
Function insert(PicPath, counter)
'MsgBox PicPath
With ActiveSheet.Pictures.insert(PicPath)
With .ShapeRange
.LockAspectRatio = msoTrue
.Width = 50
.Height = 70
End With
.Left = ActiveSheet.Range("A1" & counter).Left
.Top = ActiveSheet.Range("A1" & counter).Top
.Placement = 1
.PrintObject = True
End With
End Function
Last edited by a moderator: