Inserting PDF files into Excel via macro
Jeremie31
-
user -
user -
Hello,
I would like to be able to perform in Excel, by macro, attaching a PDF file to each row of a workbook, knowing that the file name is defined by the value of a cell. Example: if in cell A1 I have the value "BOB", I would like to insert a PDF file C://My Documents/BOB.pdf as an icon and resize it to fit inside cell B1. Likewise in A2, if the value is "SAM", the file SAM.pdf should be attached in cell B2… and so on for 120 rows.
Is this possible?
Please help!!!
Configuration: Windows XP Internet Explorer 7.0
I would like to be able to perform in Excel, by macro, attaching a PDF file to each row of a workbook, knowing that the file name is defined by the value of a cell. Example: if in cell A1 I have the value "BOB", I would like to insert a PDF file C://My Documents/BOB.pdf as an icon and resize it to fit inside cell B1. Likewise in A2, if the value is "SAM", the file SAM.pdf should be attached in cell B2… and so on for 120 rows.
Is this possible?
Please help!!!
Configuration: Windows XP Internet Explorer 7.0
3 answers
-
Hello
I’d like to be able to insert it as an icon
Which icon do you want to put because a PDF file doesn’t contain one?
Wouldn’t it be better to use a hyperlink to open it?
resize it to fit into cell B1
Do you want the file name to be visible in full?
If you’re going to go to the same directory every time, what’s the point?
If you have "BOB" in a cell, you can very well open C://My Documents/BOB.pdf, without changing anything but by using a small macro or by modifying your cell to manually enter a hyperlink or by macro.
Up to you to tell us.
--
Always zen -
Actually, I would like to develop a macro that automatically does what we can do manually by inserting, object, insert as icon (and link to the file) a file, which in this case is a PDF. It happens that the names of the files to attach are the same as the ones found in the cells of the first column, but creating a hyperlink would not work in my case because the Excel workbook is intended to travel to several computers that will not have the PDF files referenced by the link saved.
Hmm I hope that is clear enough!!
thanks for your help!!! -
hello
Indeed this time it’s clearer for me and I’m giving you the macro I wrote, to insert into a module.
I use Foxit for PDFs and it’s up to you to replace the path with your own PDF readerSub link_pdf() Dim lig As Long Dim ico As String Dim nom As String Dim rep As String ' modify with the right path ico = "C:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe" rep = "C:\Mes documents\" For lig = 1 To Cells(1, 1).SpecialCells(xlCellTypeLastCell).Row nom = Cells(lig, 1).Value ActiveSheet.OLEObjects.Add( _ Filename:=rep & "\" & nom & ".pdf", _ Link:=True, _ DisplayAsIcon:=True, _ IconFileName:=ico, _ IconIndex:=0, _ IconLabel:=nom).Select Selection.Left = Cells(lig, 2).Left Selection.Top = Cells(lig, 2).Top Selection.Height = Cells(lig, 2).Height Selection.Width = Cells(lig, 2).Width Next lig End Sub
the Excel workbook is intended to travel to multiple computers that will not have the PDFs files relative to the link saved.
There I’m not at all sure it works because what’s saved is indeed a link and not the PDF itself.
So on other machines I strongly doubt that the opening will work unless you integrate the files concerned.
--
Always zen