Kristie390
New Member
- Joined
- Jul 23, 2018
- Messages
- 24
I had a lot of help getting this sub working on here so I thought I would ask for one more additional mod to get this going,
I have code below to look for an image of a sku in a specific folder in our server and insert /autosize - but the issue i have is that if I send this spreadsheet to anyone else not on the server, they cannot see images. Can someone help fix this so it inserts the image dynamically? I believe this is what has to be done to place the actual image in the sheet rather than link-back when the sheet is updated/Opened. Or, how can I format this to send out and include images if they are not linked to the server? I have looked at other posts which refer to inserting dynamically but I cant get anything to work
Sub Imageupdate()
' inserts the picture files listed in col A into the workbook,
' and sizes and centers in col B
Const sPath As String = "S:\Images\Bulova"
'Const sPath As String = "C:\Users\shg\Pictures\shg"
Dim cell As Range
Dim sFile As String
Dim oPic As Picture
For Each cell In Range("A2", Cells(Rows.Count, "A").End(xlUp))
sFile = sPath & cell.Text & ".jpg"
If Len(Dir(sFile)) Then
Set oPic = ActiveSheet.Pictures.Insert(sFile)
oPic.ShapeRange.LockAspectRatio = msoTrue
With cell.Offset(, 1)
If oPic.Height > .Height Then oPic.Height = .Height
If oPic.Width > .Width Then oPic.Width = .Width
oPic.Top = .Top + .Height / 2 - oPic.Height / 2
oPic.Left = .Left + .Width / 2 - oPic.Width / 2
End With
Else
cell.Select
MsgBox sFile & " not found"
End If
Next cell
End Sub
I have code below to look for an image of a sku in a specific folder in our server and insert /autosize - but the issue i have is that if I send this spreadsheet to anyone else not on the server, they cannot see images. Can someone help fix this so it inserts the image dynamically? I believe this is what has to be done to place the actual image in the sheet rather than link-back when the sheet is updated/Opened. Or, how can I format this to send out and include images if they are not linked to the server? I have looked at other posts which refer to inserting dynamically but I cant get anything to work
Sub Imageupdate()
' inserts the picture files listed in col A into the workbook,
' and sizes and centers in col B
Const sPath As String = "S:\Images\Bulova"
'Const sPath As String = "C:\Users\shg\Pictures\shg"
Dim cell As Range
Dim sFile As String
Dim oPic As Picture
For Each cell In Range("A2", Cells(Rows.Count, "A").End(xlUp))
sFile = sPath & cell.Text & ".jpg"
If Len(Dir(sFile)) Then
Set oPic = ActiveSheet.Pictures.Insert(sFile)
oPic.ShapeRange.LockAspectRatio = msoTrue
With cell.Offset(, 1)
If oPic.Height > .Height Then oPic.Height = .Height
If oPic.Width > .Width Then oPic.Width = .Width
oPic.Top = .Top + .Height / 2 - oPic.Height / 2
oPic.Left = .Left + .Width / 2 - oPic.Width / 2
End With
Else
cell.Select
MsgBox sFile & " not found"
End If
Next cell
End Sub