Consulting

Results 1 to 12 of 12

Thread: Solved: ShellExecute for PDF documents with OpenActions

  1. #1

    Solved: ShellExecute for PDF documents with OpenActions

    Hopefully some of you smart Excel VBA programmers can help with this one.

    Hi! I'm currently working on a VBA project within ArcMap. Although many of you will be unfamiliar with this program, my question can be extended to most of you since ShellExecute can be used for programs that support VBA.

    My previous design was simplified, and used the standard 'Shell' command. I was able to pass OpenActions without any difficulties. The code for this was:

    [vba]
    Dim strPath1, strPath2, strPath3 as string

    strPath1 = """C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe"""
    strPath2 = "/A page=13=OpenActions""
    strPath3 = "C:\DocumentA.pdf"

    Shell strPath1 & " " & strPath2 & " " & strPath3, vbNormalFocus
    [/vba]
    This worked like a charm. However, it's extremely limiting as the program cannot easily be distributed since it requires Adobe Reader 9.0.
    After some research I discovered that ShellExecute can perform this task using any version of Reader, however it seems to be unable to accept the OpenActions (in this situation page #). Here's the code for the ShellExecute command.

    [vba]
    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

    Private Sub cmdPDF_Click()

    nDT = GetDesktopWindow()

    nApp = ShellExecute(nDT, "Open", "C:\DocumentA.pdf", "", "C:\", SW_SHOWNORMAL)
    End Sub
    [/vba]
    I've tried several different methods, placing the 'OpenAction' in several different places with no success. If anyone can tell me...

    a) If it's possible to use OpenActions with the ShellExecute

    b) How to solve this issue if it is

    Cheers,
    Cameron

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    You have two posts and they are both identical in different forums. Not nice. I have deleted your other post.

    Please do not do this again.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Sorry about that. I wasn't entirely sure where to make the post as the topic spans many programs that use VBA. It wont happen again.

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    If you feel the need to spread your question please just post a thread for instance in the excel forum with a link to your question.

    The problem is that you get different people trying to help you and they don't know what has already beed addressed.

    Thanks for understanding.

    I have no knowledge of the app that you mention but we do have some smart guys on shellExecute who will probably try to offer suggestions.

    Welcome to the board and I apologize if I was short in my first response.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Are you getting any kind of error? I ran your code in the shellexecute and it took a while to load but it worked.

    Hey Steve are you keeping busy?

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Hi Tommy, great to catch you. I have been out of pocket for a few weeks......just read your email yesterday..

    It's gotten really slow for me the last few months. How about yourself, staying hooked up?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    Hey Tommy

    I should have been a bit more clear. That code for ShellExecute works perfectly fine. What I need to do is add an OpenAction parameter for the pdf document.

    <partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf>

    This is what I'm currently having difficulty completing.

    Cheers,
    Cameron

  8. #8
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Peanutmc, I will have to try at home I have the full suite of adobe and it keeps firing the acrobat version 6. So if some else can help ......


    Hey Steve,

    We're working 50's and still can't get it all done. We have 4 jobs with valleys and I get to train 2 nubees on how to detail them. They both are pretty sharp, and are ready so I may be out of pocket myself fro a few weeks LOL.

  9. #9
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    I hate to say it but this is the only way I could get it to work. I hope someone else will have a berrter solution.
    [VBA]
    Sub v()

    Dim strPath1, strPath2, strPath3 As String
    Dim RetVal
    RetVal = 0
    On Error Resume Next
    strPath1 = "C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe"
    strPath2 = "/A page=13=OpenActions"
    strPath3 = "C:\DocumentA.pdf"
    RetVal = Shell(strPath1 & " " & strPath2 & " " & strPath3, vbNormalFocus)
    If RetVal = 0 Then
    strPath1 = "C:\Program Files\Adobe\Reader 7.0\Reader\AcroRd32.exe"
    RetVal = Shell(strPath1 & " " & strPath2 & " " & strPath3, vbNormalFocus)
    End If
    If RetVal = 0 Then
    strPath1 = "C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe"
    RetVal = Shell(strPath1 & " " & strPath2 & " " & strPath3, vbNormalFocus)
    End If
    If RetVal = 0 Then Call MsgBox("Unable to open PDF File!", vbExclamation, "Bad PDF File!")
    On Error GoTo 0
    End Sub

    [/VBA]

  10. #10
    Thanks for the input Tommy. I had considered this option as well, and currently I'm using it. I am however going to contribute a couple hours and attempt to tackle this a slightly different way.

    If I manage to get it working, I'll share the code. I know most of the people using the form are unfamiliar with ArcGIS. That being said, the code generating should be compatible with most VBA programs.

  11. #11
    Well after much frustration and few successes, I've finally been able to pass parameters for a PDF while opening Acrobat from its default location via the registry. I'm certain there are other methods to do this, but this method is short and sweet.

    I'm posting this with the assumption that it will likely work with other programs that can pass command line parameters. Also, I expect this solution could be used for most if not all programs incorporating VBA.

    VBA is highly limited by its access to APIs. These can be manually coded, but can be extremely time consuming and confusing. Fortunately, the procedure required for ShellExecute, through the Shell32.dll (or Shell.dll on 16bit), is reasonably simple.

    SOLUTION

    [vba]
    Option Explicit
    'Declare the ShellExecute function by accessing the Shell library's procedure
    Private Declare Function ShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" _
    'Declare arguments
    (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

    'Used to display a window
    Const SW_SHOWNORMAL = 1

    'Open pdf occurs on button click
    Private Sub cmdPDF_Click()
    Dim strPath, strParam As String

    strPath = "C:\Example.pdf"
    strParam = " /A " & Chr(34) & "page=14" & Chr(34) & strPath

    Call ShellExecute(0&, "open", "AcroRd32.exe", strParam, "", SW_SHOWNORMAL)
    End Sub
    [/vba]
    Hopefully this can help someone else out!

    Cheers,
    Cameron

  12. #12
    thanks aswell really interesting

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •