Identify application version (not Excel)

R

Ray

Hi -

I've built a dashboard that contains, among other things, links to
external files. Most of these files are excel, but a couple are
PDFs. I built some code to open the selected file, including a hard-
coded path to Acrobat Reader. The problem is that I assumed that all
users would using the same version of Acrobat Reader and apparently,
we're not ... so now need to modify the code to identify the version
number and use it in the code. Current code is as follows:

[Note: XLfile and YBook are publicly declared variables]
**********************************************
Sub OpenYBook()

Dim dbRetValue As Double
Dim stAdobeExe As String, stFileName As String

stAdobeExe = "C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe"

If Dir(XLfile & YBook) <> "" Then
dbRetValue = Shell(stAdobeExe & " " & XLfile & YBook,
vbMaximizedFocus)
Else
MsgBox "The following report isn't currently available:" & Chr(10)
& _
YBook & Chr(10) & Chr(10) & _
"Please check again later!", vbExclamation + vbOKOnly, "File
Not Available"
End If
End Sub
**********************************************
So, instead of hard-coding 'Reader 9.0', the code should identify what
version is available (currently 8.0 and 9.0) and then open that one.
I could use an if/then to open the files, but I expect we'll upgrade
at some point and then the code won't work again.

Thanks your help!

br//ray
 
R

Ray

John -

My code works ok, but assumes that the user has Reader 9.0
installed ... if they have 8.0, the 'file not found' error pops up.
So, basically, I need the macro to find the Reader X.XX file, parse
out the X.XX and assign it to variable, which would then take the
place of the hard-coded Reader 9.0 part of the code.

//ray
 
R

Rick Rothstein

You should be able to use this code to open the file without having to know
the version of Adobe Reader they are using. Copy/Paste this code in a
standard Module (Insert/Module from the VB editor's menu bar)...

Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long

Sub OpenThisFile(PathAndFilename)
ShellExecute 0, "", """" & PathAndFilename & """", "", "", vbNormalFocus
End Sub

and then from your own code, just call the OpenThisFile subroutine passing
it your filename complete with its path. So, if (as per your original
message) the filename and its path is this...

XLfile & YBook

then you would open it like this...

OpenThisFIle XLfile & YBook
 
R

Rick Rothstein

The problem with that first link is that you have to register with the site,
which many people do not like to do (me for instance<g>).
 
J

John Bundy

You don't have to register with the site to use it, I thought you had to
myself and was happy to find that if you just scroll all of the way down, the
answers are there. Great resource.
 
J

John Bundy

Very strange, if i click the link the answers are indeed not there. If you
arrive there through Google of Bing the answers are. If you take the question
and plug it into Google for example, the first hit is it and you can enter
and scroll down and read the answer.
"Open an existing PDF document from VB.net using OLE automation" try it.
Next time I will post the code and the link.
Very weird.
 
R

Rick Rothstein

What text did you type into Google or Bing to get that to happen? Everything
I try takes me to a page that says I have to sign up to see the answers from
their experts?

I note in the title for the article that it says "VB.net"... Is that code
easy to convert to VBA? Just out of curiosity (assuming I won't be able to
see the article at that website for myself), is the code shorter than the
method I posted in this thread?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top