Solved

Embeded Files within an Excel Document - Code not working.

Posted on 2011-03-24
5
704 Views
Last Modified: 2012-05-11
Hi there,

Up until recently, I used to embed PDF files into an Excel document whith the code below:

Sub Embed()
Dim strFileName As String, strTitle As String
Dim objOLE As OLEObject

On Error GoTo Handler
strFileName = Application.GetOpenFilename("PDF Files (*.pdf), *.pdf")
strTitle = Mid$(strFileName, InStrRev(strFileName, "\") + 1)

 
ActiveSheet.OLEObjects.Add Filename:=strFileName, Link:=False, DisplayAsIcon:=True, _
    IconIndex:=5, IconFileName:="C:\windows\installer\$PatchCache$\Managed\68AB67CA7DA73301B7449A0300000010\9.3.0\acrord32.dll", _
    IconLabel:=strTitle

With objOLE
        .Top = cell.center
        .Left = cell.center
        ' uncomment next two lines if you want to fit to the cell exactly
        .Height = cell.Height
        .Width = cell.Width
    End With
 
Exit Sub
 
Handler:
End Sub

Open in new window


This was linked to a button that, when clicked would bring up the Browse Files windows and allow you to embed the file into the Excel document.

I have now discovered that this isnt working on some computers and I have narrowed it down to machines with Acrobat X installed which clearly negates the line:

IconFileName:="C:\windows\installer\$PatchCache$\Managed\68AB67CA7DA73301B7449A0300000010\9.3.0\acrord32.dll", _

Open in new window


What would be the best way to rectify this? Is there any way I can link to a server shared .ico file? Like \\servername\share\pdf.ico?

I found this code a while back and cannot claim to be a master coder, would it be possible for someone to take a look and let me know how to resolve it so all machines can use it, regardless of Acrobat being installed or not?
0
Comment
Question by:ultra-it
  • 3
5 Comments
 
LVL 2

Expert Comment

by:JanEnEm
ID: 35205670
Having taken a quick lance at the code:
The ActiveSheet.OLEObjects.Add statements specifies a file loccation for the iconfile name refereing to Acrobat 9/ Would that be the problem when using Acrobat X?
Especially when the location does not exist (anymore)?

Jan Meijer
0
 

Accepted Solution

by:
ultra-it earned 0 total points
ID: 35205827
I was indeed aware of this bit, and I have replace this with a link to the old shell32.dll iconset which worked provinding you still have Acrobat Reader 9 installed, to be honest, any PDF reader worked (eCopy, PDF Complete etc) whether the icon was for the PDF icon or not (the icon rarely worked to be honest, but the file was embedded).

Reinstalling Acrobat Reader X causes the problem once more where nothing is embedded at all.

I have noticed that Acrobat is running in the Task Manger, so for some reason it is calling Acrobat X to embed the file.

Here is the code I am now using:

Sub Embed()
Dim strFileName As String, strTitle As String
Dim objOLE As OLEObject

On Error GoTo Handler
strFileName = Application.GetOpenFilename("PDF Files (*.pdf), *.pdf")
strTitle = Mid$(strFileName, InStrRev(strFileName, "\") + 1)

 
ActiveSheet.OLEObjects.Add Filename:=strFileName, Link:=False, DisplayAsIcon:=True, _
    IconIndex:=54, IconFileName:="C:\windows\system32\shell32.dll", _
    IconLabel:=strTitle

With objOLE
        .Top = cell.center
        .Left = cell.center
        ' uncomment next two lines if you want to fit to the cell exactly
        .Height = cell.Height
        .Width = cell.Width
    End With
 
Exit Sub
 
Handler:
End Sub

Open in new window


Without the obvious reference to the PDF filetype near the top, is there any reason Acrobat would be called by this code?

Clearly, the easiest thing to do is ensure users do not upgrade to Reader X, but 9 is quite old now.

Just looking for a work around if any.
0
 
LVL 2

Expert Comment

by:JanEnEm
ID: 35207294
@ultra-it:

The code seems normal to met too.
The only thing I can think of is that the VBA code may interact with Adobe, once it discovers a filetype of PDF is encountered, simply because the filetype is associated to Adobe.

I have no further in depth knowledge of the behavior of the VBA interpreter.

May try it out with a non-PDF style document. But you may have already tried that one out...

Regards

Jan Meijer
0
 
LVL 2

Expert Comment

by:JanEnEm
ID: 35285751
Hi,

I would suggest to keep the entry available for others. I know all too well that sometimes you can hit an entry in the EE database that explains why you have run into problems. Even when a little bit off subject.
Isn't that what a knowledge database is all about?

Jan Meijer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What is format f12.8 for a CSV file 6 42
Create Excel formula on dynamic data 5 37
Split a string in excel 9 37
increment numbers by 10 11 31
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now