Adobe PDF button (1 Viewer)

radshar

Registered User.
Local time
Today, 14:34
Joined
Aug 5, 2016
Messages
32
Hello,

I used the following code below to open an excel file using a button in a form. I want a similar button to open an exisisitng PDF fillable form. How do I change the CreateObject to Adobe?


Code:
 [/FONT]
 [FONT=Calibri]Private Sub PL_Submission_Form_Click()[/FONT]
 [FONT=Calibri]Dim xlApp As Object[/FONT]
 [FONT=Calibri] [/FONT]
 [FONT=Calibri]Set xlApp = CreateObject("Excel.Application")[/FONT]
 [FONT=Calibri]xlApp.Visible = True[/FONT]
 [FONT=Calibri] [/FONT]
 [FONT=Calibri]xlApp.Workbooks.Open "C:\Users\xxxxxx\xxxxx\Worksheet in C  Users xxxxxx Desktop Report Reveiw Procedure v02.xls", True, False[/FONT]
 [FONT=Calibri] [/FONT]
 [FONT=Calibri]End Sub[/FONT]
 [FONT=Calibri]
 

Ranman256

Well-known member
Local time
Today, 17:34
Joined
Apr 9, 2015
Messages
4,339
You only need 1 button to do it all.
Paste this code into a module, and it will open ANY file in its native application.
usage:
OpenNativeApp "c:\folder\file.pdf"
will open it in acrobat
and
OpenNativeApp ME.txtBox
will open the doc in Word if the item in txtBox is C:\myfile.doc

Code:
'Attribute VB_Name = "modNativeApp"
'Option Compare Database
Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long

Private Declare Function GetDesktopWindow Lib "user32" () As Long
Const SW_SHOWNORMAL = 1
Const SE_ERR_FNF = 2&
Const SE_ERR_PNF = 3&
Const SE_ERR_ACCESSDENIED = 5&
Const SE_ERR_OOM = 8&
Const SE_ERR_DLLNOTFOUND = 32&
Const SE_ERR_SHARE = 26&
Const SE_ERR_ASSOCINCOMPLETE = 27&
Const SE_ERR_DDETIMEOUT = 28&
Const SE_ERR_DDEFAIL = 29&
Const SE_ERR_DDEBUSY = 30&
Const SE_ERR_NOASSOC = 31&
Const ERROR_BAD_FORMAT = 11&


Public Sub OpenNativeApp(ByVal psDocName As String)
Dim r As Long, msg As String

r = StartDoc(psDocName)
If r <= 32 Then
    'There was an error
    Select Case r
        Case SE_ERR_FNF
            msg = "File not found"
        Case SE_ERR_PNF
            msg = "Path not found"
        Case SE_ERR_ACCESSDENIED
            msg = "Access denied"
        Case SE_ERR_OOM
            msg = "Out of memory"
        Case SE_ERR_DLLNOTFOUND
            msg = "DLL not found"
        Case SE_ERR_SHARE
            msg = "A sharing violation occurred"
        Case SE_ERR_ASSOCINCOMPLETE
            msg = "Incomplete or invalid file association"
        Case SE_ERR_DDETIMEOUT
            msg = "DDE Time out"
        Case SE_ERR_DDEFAIL
            msg = "DDE transaction failed"
        Case SE_ERR_DDEBUSY
            msg = "DDE busy"
        Case SE_ERR_NOASSOC
            msg = "No association for file extension"
        Case ERROR_BAD_FORMAT
            msg = "Invalid EXE file or error in EXE image"
        Case Else
            msg = "Unknown error"
    End Select
'    MsgBox msg
End If
End Sub
 

radshar

Registered User.
Local time
Today, 14:34
Joined
Aug 5, 2016
Messages
32
THanks,

the code is stopping at the below, with the error "sub or function not defined"...any idea why?

Code:
r = StartDoc(psDocName)[CODE]
  
 [QUOTE="Ranman256, post: 1501177, member: 138398"]You only need 1 button to do it all.
Paste this code into a module, and it will open ANY file in its native application.
usage: 
OpenNativeApp "c:\folder\file.pdf"
will open it in acrobat
and 
OpenNativeApp ME.txtBox
will open the doc in Word if the item in txtBox is C:\myfile.doc

[code]
'Attribute VB_Name = "modNativeApp"
'Option Compare Database
Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long

Private Declare Function GetDesktopWindow Lib "user32" () As Long
Const SW_SHOWNORMAL = 1
Const SE_ERR_FNF = 2&
Const SE_ERR_PNF = 3&
Const SE_ERR_ACCESSDENIED = 5&
Const SE_ERR_OOM = 8&
Const SE_ERR_DLLNOTFOUND = 32&
Const SE_ERR_SHARE = 26&
Const SE_ERR_ASSOCINCOMPLETE = 27&
Const SE_ERR_DDETIMEOUT = 28&
Const SE_ERR_DDEFAIL = 29&
Const SE_ERR_DDEBUSY = 30&
Const SE_ERR_NOASSOC = 31&
Const ERROR_BAD_FORMAT = 11&


Public Sub OpenNativeApp(ByVal psDocName As String)
Dim r As Long, msg As String

r = StartDoc(psDocName)
If r <= 32 Then
    'There was an error
    Select Case r
        Case SE_ERR_FNF
            msg = "File not found"
        Case SE_ERR_PNF
            msg = "Path not found"
        Case SE_ERR_ACCESSDENIED
            msg = "Access denied"
        Case SE_ERR_OOM
            msg = "Out of memory"
        Case SE_ERR_DLLNOTFOUND
            msg = "DLL not found"
        Case SE_ERR_SHARE
            msg = "A sharing violation occurred"
        Case SE_ERR_ASSOCINCOMPLETE
            msg = "Incomplete or invalid file association"
        Case SE_ERR_DDETIMEOUT
            msg = "DDE Time out"
        Case SE_ERR_DDEFAIL
            msg = "DDE transaction failed"
        Case SE_ERR_DDEBUSY
            msg = "DDE busy"
        Case SE_ERR_NOASSOC
            msg = "No association for file extension"
        Case ERROR_BAD_FORMAT
            msg = "Invalid EXE file or error in EXE image"
        Case Else
            msg = "Unknown error"
    End Select
'    MsgBox msg
End If
End Sub
[/QUOTE]
 

Users who are viewing this thread

Top Bottom