Jimmypop
Well-known Member
- Joined
- Sep 12, 2013
- Messages
- 753
- Office Version
- 365
- Platform
- Windows
Good day
I have the following code which was obtained somewhere on the net (cant remember where). It works perfectly for what I want to do.
However when sending the file to another user, the pictures disappear and it says that the linked image cannot be displayed it may have been moved. How would code change to prevent this?
I have the following code which was obtained somewhere on the net (cant remember where). It works perfectly for what I want to do.
However when sending the file to another user, the pictures disappear and it says that the linked image cannot be displayed it may have been moved. How would code change to prevent this?
VBA Code:
Sub Insert_Picture()
On Error GoTo ErrorHandler
result = MsgBox("Do you want to upload a picture?", vbYesNo + vbQuestion, "Message from VFL...")
If result = vbYes Then
Const cBorder As Double = 5 ' << change as required
Dim sPicture As String, pic As Picture
sPicture = Application.GetOpenFile("Pictures (*.png; *.gif; *.jpg; *.bmp; *.tif), *.gif; *.jpg; *.bmp; *.tif", , "Select Picture to Import")
If sPicture = "False" Then Exit Sub
Set pic = ActiveSheet.Pictures.Insert(sPicture)
With pic
.ShapeRange.LockAspectRatio = False ' << change as required
If Not .ShapeRange.LockAspectRatio Then
.Width = ActiveCell.MergeArea.Width - (2 * cBorder)
.Height = ActiveCell.MergeArea.Height - (2 * cBorder)
Else
If .Width >= .Height Then
.Width = ActiveCell.MergeArea.Width - (2 * cBorder)
Else
.Height = ActiveCell.MergeArea.Height - (2 * cBorder)
End If
End If
.Top = ActiveCell.MergeArea.Top + cBorder
.Left = ActiveCell.MergeArea.Left + cBorder
.Placement = xlMoveAndSize
End With
Set pic = Nothing
End If
ErrorHandler: Exit Sub
End Sub