mehidy1437
Active Member
- Joined
- Nov 15, 2019
- Messages
- 348
- Office Version
- 365
- 2016
- 2013
- Platform
- Windows
- Mobile
- Web
Hi Guys,
I'm using this code to import image in excel sheets.
It's working fine.
Only issue is it's import the image as link.
But I want to bring/place the image in sheet not as a link.
So, if I send the file to any computer, picture should be always in the sheet.
I have tried to changes this part
VBA code
I'm using this code to import image in excel sheets.
It's working fine.
Only issue is it's import the image as link.
But I want to bring/place the image in sheet not as a link.
So, if I send the file to any computer, picture should be always in the sheet.
I have tried to changes this part
with thisWith ActiveSheet.Pictures.insert(PicPath)
But it's not import any pictureWith ActiveSheet.Shapes.AddPicture(fileName:=PicPath, LinkToFile:=False, SaveWithDocument:=True)
VBA code
VBA Code:
Sub AddOlEObject()
Dim mainWorkBook As Workbook
Set mainWorkBook = ActiveWorkbook
Sheets("Object").Activate
Dim folderPath As String
folderPath = Application.InputBox("Put the folder path in inputbox")
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, "gif", 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 = 150
Sheets("Object").Range("B" & counter).Activate
Call insert(strCompFilePath, counter) '''see insert function code in below
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 = msoFalse
.Width = 130
.Height = 140
End With
'With .ShapeRange
' .LockAspectRatio = msoTrue
' .Width = 24
' .Height = 140
'End With
.Left = ActiveSheet.Range("B" & counter).Left
.Top = ActiveSheet.Range("B" & counter).Top
.Placement = 1
.PrintObject = True
End With
End Function