How to open PDF-documents from VB code? (1 Viewer)

Gerthe

New member
Local time
Today, 22:13
Joined
Dec 12, 2005
Messages
8
Hi all,

From my code, I can manage opening Microsoft documents:
After declaring variables etc it goes somehow like this (example with Word):
Set appWord = New Word.Application
Set docWord = appWord.Documents.Open(strFile, , False)
appWord.Visible = True
(where strFile is the full path and doc name)
This all works fine, but how do I open other documents, such as PDF (Adobe Reader) from my VBA - Access code? Do you have any suggestions for further readings regarding similar issues?

Thanks,
Gert
 

KenHigg

Registered User
Local time
Today, 17:13
Joined
Jun 9, 2004
Messages
13,327
I suspect you may need to do this with an ActiveX object...

Maybe google 'ActiveX pdf viewer'
 

Gerthe

New member
Local time
Today, 22:13
Joined
Dec 12, 2005
Messages
8
ok, I'll google...
 

nateobot

Registered User.
Local time
Today, 16:13
Joined
Dec 13, 2005
Messages
86
Shell "PATH TO ACROBAT READER " + sFileName

I think would work.
 

Gerthe

New member
Local time
Today, 22:13
Joined
Dec 12, 2005
Messages
8
Well well, this works!
I tested many times, one example here:
Shell "C:\Program Files\Adobe\Acrobat 7.0\Reader\Acrord32.exe + C:\Mail\Salesmat.pdf", vbNormalFocus
(all in one line)
The only problem is that Acrobat shows before opening the pdf an error message:
"There was an error opening this document. This file cannot be found.",
but then opens the correct document (!?)

I also tried with Winword. It also shows errormsg:
"The document name or path is not valid. Try..."

I noted that the word doc is not found if the path has spaces in the folder name:
"... + C:\MyDouments\Example.doc" works but
"... + C:\My Douments\Example.doc" does not work.

Anyway, I can live with this PDF case, and I'll intent to apply it to other docs, too. For users of my apps it would be nice to eliminate the error msg.

Thanks nateobot!
Gert
 

KenHigg

Registered User
Local time
Today, 17:13
Joined
Jun 9, 2004
Messages
13,327
I think you simply need to leave the '+' sign out to make this work... ??

Or maybe embed some single quotes;

"... + 'C:\My Douments\Example.doc'"

???
 

namliam

The Mailman - AWF VIP
Local time
Today, 23:13
Joined
Aug 11, 2003
Messages
11,695
Every full path name you use should allways be
1) A variable, as pathnames change...
2) Allways be quoted to get around spaces.


So to solve this one... Quote your (single) path like so:
"""....."" + """C:\My Douments\Example.doc"""

or something simular... Also I think you can/should skip the '+' but I am not sure and to lazy to try or search for you...
 

Gerthe

New member
Local time
Today, 22:13
Joined
Dec 12, 2005
Messages
8
Thanks "The Maliman" & Ken,

I just skipped the '+' , and no error messages (I tried the PDF).

Have a nice day,
Gert
 

dinger

New member
Local time
Today, 17:13
Joined
Sep 13, 2005
Messages
6
You can use the shell command

Shell "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe C:\PDF_name.pdf"
 

Bat17

Registered User.
Local time
Today, 22:13
Joined
Sep 24, 2004
Messages
1,687
or you could use the hyperlink method.
Application.FollowHyperlink "C:\PDF_name.pdf"

Peter
 

ghudson

Registered User.
Local time
Today, 17:13
Joined
Jun 8, 2002
Messages
6,195
dinger said:
You can use the shell command

Shell "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe C:\PDF_name.pdf"
What if the user has Adobe Acrobat 6.0 installed?

Some computers have a problem with the Shell command if the path or file name has a space in it.

The ShellExecute() method my sample displays will open the file with the correct executable that is registered on the users computer.
 

Gerthe

New member
Local time
Today, 22:13
Joined
Dec 12, 2005
Messages
8
Good point!, actually, there is alwasy work in order to generalize the code. Now hard-code was a good start, but you are right, lets try the suggested method. Specially true when intenting to open all kind of documents.
 

Users who are viewing this thread

Top Bottom