I have below module to insert Image into a selected merged Cell and automatically resize the image to fit either Width or Height of that Cell. But I have a problem when sending this report to my customer, they can’t see the images as my code inserted them as location path.
The only solution I have now is to “save as pdf” then the customers can see the report.
Is there a way to save my Excel file with the images so they’re still viewable when downloaded by my customers?
Sub INSERT_PIC()
Dim MyMergeCell As Range
Dim MyFile As String
Dim MyPath As String
'---------------------------------------------------------------------------
'- SELECTED CELL
Set MyMergeCell = ActiveCell
'---------------------------------------------------------------------------
'- OPEN THE FILE WITH GetOpenFilename()
MyFile = Application.GetOpenFilename("Picture Files (*.bmp;*.jpg;*.tif;*.gif), *.bmp;*.jpg;*.tif;*.gif", , " GET PICTURE", , msoTrue)
If MyFile = "False" Then Exit Sub
'----------------------------------------------------------------------------
'- INSERT THE FILE INTO THE WORKSHEET
ActiveSheet.Pictures.Insert(MyFile).Select
'----------------------------------------------------------------------------
'- RESIZE PICTURE TO MERGE CELL. REFORMAT
With MyMergeCell
Dim r As Range, sel As Shape
Set sel = ActiveSheet.Shapes(Selection.Name)
sel.LockAspectRatio = msoTrue
Set r = Range(sel.TopLeftCell.MergeArea.Address)
Select Case (r.Width / r.Height) / (sel.Width / sel.Height)
Case Is > 1
sel.Height = r.Height
Case Else
sel.Width = r.Width
End Select
sel.Top = r.Top: sel.Left = r.Left
End With
End Sub
Fail to view images from customer’s computer
Nick Vo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.