I have an addpicture VBA that functions file with a fixed filepath but i need it to reference a filepath generated by a formula in a specific cell. also need to be able to resize the image to fit the cell column width but maintain aspect ratio. I was able to do all this with PictureInsert function but then the images are not visible when the document is used by other parties...
Here is my addpicture code:
Sub URLAddPicture()
Set pic = ActiveSheet.Shapes.AddPicture("\\frb-fs01\DF\SHOEPICS\1. SHOE PHOTOS\spring summer 2020\BULK SAMPLES\DISCOVERY\AADLIA-SUBLACKEURO LEATHER.JPG", _
linktofile:=msoFalse, savewithdocument:=msoCTrue, Left:=0, Top:=0, Width:=-1, Height:=-1)
End Sub
And PictureInsert code:
Sub URLPictureInsert()
Dim Pshp As Shape
Dim xRg As Range
Dim xCol As Long
On Error Resume Next
Application.ScreenUpdating = False
Set rng = ActiveSheet.Range("A113")
For Each cell In rng
filenam = cell
ActiveSheet.Pictures.Insert(filenam).Select
Set Pshp = Selection.ShapeRange.Item(1)
If Pshp Is Nothing Then GoTo lab
xCol = cell.Column
Set xRg = Cells(cell.Row, xCol)
With Selection
.ShapeRange.LockAspectRatio = msoTrue
If (.Height \ .Width) <= (rng.Height \ rng.Width) Then
.Width = rng.Width - 1
.Left = rng.Left + 1
.Top = rng.Top + ((rng.Height - Selection.Height) / 2)
Else
.Top = rng.Top + 1
.Height = rng.Height - 1
.Left = rng.Left + ((rng.Width - Selection.Width) / 2)
End If
.Placement = xlMoveAndSize
.PrintObject = True
End With
lab:
Set Pshp = Nothing
Range("A113").Select
Next
Application.ScreenUpdating = True
End Sub
If anyone is able to assist I would be most grateful.