Forum Discussion
Embedding a picture with breaking links does not work
Apologies in advance if I don't format this discussion properly. I'm a bit of a newbie to forums.
I've automated (still prototyping) some expense report procedures. One requirement is to attach receipts to the workbook. The receipts must be self-contained in the workbook as it gets moved to a network after being generated locally on a laptop. At first I embedded PDFs, which worked--as far as embedding--but the clarity of an embedded PDF object is very poor, and unacceptable to the accounting department. When I embedded an image file (PNG or JPG), the image the quality of the image was / is satisfactory (and seemed to work), but now I find that there is no image. When I click the icon in its place the formula bar reads: =EMBED("Packager Shell Object",""). I can click the icon and the image appears, but it needs to be visible on the sheet. I don't know what a "Packager Shell Object"is; when I inserted a PDF the formula bar read: =EMBED("Acrobat Document","")
Thanks for any help you can give.
Here's my code (in part):
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "Select Scan"
.Filters.Clear
.Filters.Add "JPG Images (*.JPG)", "*.jpg"
.Filters.Add "PNG Images (*.PNG)", "*.png"
.FilterIndex = 2
.AllowMultiSelect = False
.InitialFileName = ""
result = .Show
If (result <> 0) Then
fnameAndPath = Trim(.SelectedItems.Item(1))
sheetName = CreateNewWorksheet("scan")
wkbk.Worksheets(sheetName).Activate
Set Ol = ActiveSheet.OLEObjects.Add(fileName:=fnameAndPath, Link:=False, DisplayAsIcon:=False)
With ActiveSheet.PageSetup
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
wkbk.Worksheets("Expense_Report").Activate
Application.EnableEvents = True
Exit Sub
Else
'no file was selected
MsgBox "No file selected"
Exit Sub
End If
Change
Set Ol = ActiveSheet.OLEObjects.Add(Filename:=fnameAndPath, Link:=False, DisplayAsIcon:=False)
to
ActiveSheet.Shapes.AddPicture Filename:=fnameAndPath, LinktoFile:=False, _ SaveWithDocument:=True, Left:=10, Top:=10, Width:=400, Height:=300
Adjust the position and size as needed.
2 Replies
Change
Set Ol = ActiveSheet.OLEObjects.Add(Filename:=fnameAndPath, Link:=False, DisplayAsIcon:=False)
to
ActiveSheet.Shapes.AddPicture Filename:=fnameAndPath, LinktoFile:=False, _ SaveWithDocument:=True, Left:=10, Top:=10, Width:=400, Height:=300
Adjust the position and size as needed.
- 750mlCopper Contributor
Thanks for the help - I'd already begun going down the "addpicture" path for a bit. I'll test