Solved

Embeded Files within an Excel Document - Code not working.

Posted on 2011-03-24
5
689 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
Comment Utility
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
Comment Utility
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
Comment Utility
@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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

771 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

11 Experts available now in Live!

Get 1:1 Help Now