help????

loloslikes
03-31-2003, 04:09 PM
How would I be able to click a command button in a dialog box created in the Visual Basic Editor and have that action bring/open up a pdf file in a folder on my computer???

I have tried this and does not work! This is put into the command buttons click event procedure!!!

Dim myFile as String, getMyFile as Object

myFile = "location of file on computer.pdf"

getMyFile.Open myFile

*****I think I am barking up the wrong tree******

any help welcome

Legend
03-31-2003, 06:38 PM
Firstly, you actually need to tell your host application what type of object that your object is, and set it to use it. Do a search on these forums for CreatObject for some examples.


Here is some code that might help...


Private Sub Command1_Click()
Dim gApp As Acrobat.CAcroApp
Dim gPDDoc As Acrobat.CAcroPDDoc


Set gApp = CreateObject("AcroExch.App")
Set gPDDoc = CreateObject("AcroExch.PDDoc")
If gPDDoc.Open("c:\adobe.pdf") Then
gApp.Show
End If
End Sub


Note that you have to set references in your VBA Project to access the Adobe PDF type library. You will need to download these from Adobe I think....

loloslikes
03-31-2003, 07:04 PM
Thanks Legend I will mess around with it a little. I quite don't understand everything you did so if you have some spare time could you document your example code. I would really appreciate it. Thanks again

Firstly, you actually need to tell your host application what type of object that your object is, and set it to use it. Do a search on these forums for CreatObject for some examples.


Here is some code that might help...


Private Sub Command1_Click()
Dim gApp As Acrobat.CAcroApp
Dim gPDDoc As Acrobat.CAcroPDDoc


Set gApp = CreateObject("AcroExch.App")
Set gPDDoc = CreateObject("AcroExch.PDDoc")
If gPDDoc.Open("c:\adobe.pdf") Then
gApp.Show
End If
End Sub


Note that you have to set references in your VBA Project to access the Adobe PDF type library. You will need to download these from Adobe I think....

Legend
03-31-2003, 07:45 PM
Looking into this further, the method I gave you above requires that you have the acrobat software development kit installed. Its free, but if all you ever want to do with .PDF files is open them from Excel, then its probably overkill. However, if you want to downlaod the kit, you can do so here (http://partners.adobe.com/asn/acrobat/download.jsp).

An 'easier' method maybe to use the "shellexecute" method:


Public 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 Open_PDF()
ShellExecute 0, "open", "C:\test.pdf", "", "", 1
End Sub


This is a bit easier, and will work as long as Adobe Acrobat is installed on your PC. :)

loloslikes
04-01-2003, 08:10 AM
The code below seems to work and it opens my pdf file, but I have Adobe Acrobat 5.0 installed on my machine. Will this still work if I have only Acrobat Reader installed? I need this to open for computers with just acrobat reader installed.....or is the only why to have other computers install acrobat software development kit or adobe acrobat
*********************************************
This is in the command buttons click event:

'for tutorial
Dim AcroExchApp As Object
Dim AcroExchAVDoc As Object
Dim strFileName As String

Set AcroExchApp = CreateObject("AcroExch.App")
Set AcroExchAVDoc = CreateObject("AcroExch.AVDoc")

'show the Acrobat Exchange Window
AcroExchApp.Show

'set the filename to be opened
strFileName = "C:\Documents and Settings\tutorial.pdf"

'open the pdf file
AcroExchAVDoc.Open strFileName, vbNull
**************************************************
Thanks Legend...your the man

Looking into this further, the method I gave you above requires that you have the acrobat software development kit installed. Its free, but if all you ever want to do with .PDF files is open them from Excel, then its probably overkill. However, if you want to downlaod the kit, you can do so here (http://partners.adobe.com/asn/acrobat/download.jsp).

An 'easier' method maybe to use the "shellexecute" method:


Public 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 Open_PDF()
ShellExecute 0, "open", "C:\test.pdf", "", "", 1
End Sub


This is a bit easier, and will work as long as Adobe Acrobat is installed on your PC. :)

Legend
04-01-2003, 12:40 PM
I honestly don't know if that code will work with acrobat reader. I think that it actually requires the acrobat.tlb library (did you have to set it under 'references' in excel to get your code to work?)

If acrobat reader doesn't include that file, then it probably won't work. However, you can always distribute it with your workbook :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum