Results 1 to 3 of 3
  1. #1
    Etoimos is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Mar 2020
    Posts
    249

    Can not open PDF file via Shell

    I'm trying to create a button that when clicked will open a .pdf file in Acrobat. This is the code that I'm using:

    Code:
    Shell "Acrobat.exe \\one.mda.mil\Public\OPIR\Lab_Ops_Formerly_TSC\Printed_Documents\test.pdf", vbNormalFocus
    Access gives me an error 53, file not found error, but I know the file is there. I have successfully used the following code to open both Excel and Word files from that same directory:

    Excel file
    Code:
    Shell "EXCEL.EXE \\one.mda.mil\Public\OPIR\Lab_Ops_Formerly_TSC\Printed_Documents\test.xlsx", vbNormalFocus
    Word file


    Code:
    Shell "WINWORD.EXE \\one.mda.mil\Public\OPIR\Lab_Ops_Formerly_TSC\Printed_Documents\MasterEventDoneFile.doc", vbNormalFocus

    Is there something unique about opening a PDF that I'm missing?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    usage: OpenNativeApp txtBox

    OpenNativeApp "c:\folder\file.pdf"
    will open it in acrobat


    OpenNativeApp "c:\folder"
    will open the folder


    OpenNativeApp "www.google.com"
    will open web browser.



    'Paste this code into a module, and it will open ANY file in its native application.
    Code:
    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
    Code:
    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
    

  3. #3
    Etoimos is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Mar 2020
    Posts
    249
    I've never done any coding in a Module, do both sets of code that you posted go into the same module? Is there anything that separates them (or why did you post them in separate code sections)?

    I also do not understand your "usage: OpenNativeApp txtBox" statement. Does that mean it will only work with a textbox?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 08-14-2020, 06:55 PM
  2. Shell comand to open program in Win 10
    By MadTom in forum Programming
    Replies: 5
    Last Post: 03-04-2020, 08:47 AM
  3. Workbooks.Open won't open Excel file in Edit Mode
    By jeffhanner10@gmail.com in forum Programming
    Replies: 5
    Last Post: 02-15-2020, 11:51 AM
  4. Replies: 7
    Last Post: 06-18-2012, 11:31 AM
  5. Open (shell) a program and pass a file
    By Olszanski in forum Programming
    Replies: 2
    Last Post: 07-27-2010, 03:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums