Last active
November 13, 2020 06:08
-
-
Save thmain/642245a07729be7b16e95baf5cff9cb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub AddOlEObject() | |
Dim mainWorkBook As Workbook | |
Set mainWorkBook = ActiveWorkbook | |
Sheets("Object").Activate | |
Folderpath = "C:\Users\Sumit Jain\Pictures" | |
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("Object").Range("A" & counter).Value = fls.Name | |
Sheets("Object").Range("B" & counter).ColumnWidth = 25 | |
Sheets("Object").Range("B" & counter).RowHeight = 100 | |
Sheets("Object").Range("B" & counter).Activate | |
Call insert(strCompFilePath, counter) | |
Sheets("Object").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("B" & counter).Left | |
.Top = ActiveSheet.Range("B" & counter).Top | |
.Placement = 1 | |
.PrintObject = True | |
End With | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this like says : Run-time error '13: Type mismatch
Any ideas?