I am after some help if i may.
I'm very new to VBA & trying to get my head round it with not a lot of sucsses.
I can edit & add to already written codes so they meet my needs but i have hit a brick wall with this 1.
I have a great code found on this forum written by @Domenic MrExcel MVP
It inserts pictures in a grid format but the problem is it uses .Pictures.Insert so the pictures are linked to a folder.
I need them to embed to the Excel workbook.
In the past i have been able achieve this by using the .AddPicture then LinkToFile set as True.
I have tried changing this code but am getting errors. I can only assume it is to do with how the code gets the file names?
Cant work out what the (i) is or how i would use it with .AddPicture
The code is a bit over my head if im honest & i could do with some help please.
Thanks in advance
I'm very new to VBA & trying to get my head round it with not a lot of sucsses.
I can edit & add to already written codes so they meet my needs but i have hit a brick wall with this 1.
I have a great code found on this forum written by @Domenic MrExcel MVP
It inserts pictures in a grid format but the problem is it uses .Pictures.Insert so the pictures are linked to a folder.
I need them to embed to the Excel workbook.
In the past i have been able achieve this by using the .AddPicture then LinkToFile set as True.
I have tried changing this code but am getting errors. I can only assume it is to do with how the code gets the file names?
Cant work out what the (i) is or how i would use it with .AddPicture
The code is a bit over my head if im honest & i could do with some help please.
Thanks in advance
Code:
Sub InsertPictures()
Dim vFilename As Variant
Dim oPic As Picture
Dim StartRow As Long
Dim StartCol As Long
Dim NumCols As Long
Dim i As Long
Dim r As Long
Dim c As Long
vFilename = Application.GetOpenFilename( _
FileFilter:="Pictures (*.gif;*.jpg;*.png), *.gif;*.jpg;*.png", _
Title:="Select Picture", _
MultiSelect:=True) 'change the file filter accordingly
If Not IsArray(vFilename) Then Exit Sub
StartRow = 5 'change the start row accordingly
StartCol = 1 'change the start column accordingly
NumCols = 3 'change the number of columns accordingly
r = StartRow
c = StartCol
For i = LBound(vFilename) To UBound(vFilename)
Set oPic = ActiveSheet.Pictures.Insert(vFilename(i))
With oPic
.ShapeRange.LockAspectRatio = msoFalse
.Left = Cells(r, c).MergeArea.Left
.Top = Cells(r, c).MergeArea.Top
.Width = Cells(r, c).MergeArea.Width
.Height = Cells(r, c).MergeArea.Height
End With
If i Mod NumCols = 0 Then
r = r + 13
c = StartCol
Else
c = c + 6
End If
Next i
End Sub