Solved

Embeded Files within an Excel Document - Code not working.

Posted on 2011-03-24
5
712 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

770 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