Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Embeded Files within an Excel Document - Code not working.

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

792 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