none
Shell command & VBA RRS feed

  • Question

  • Not precisely a Word VBA specific issue/question, but since I'm working in Word I'll ask here. What follows is a section of code I am running:

    Dim sPath As String
    
    Select Case Me.mMain.Pages(mMain.Value).Controls(0).Column(2)
        Case Is = "WORD"
            Application.Documents.Add "\\mg.local\config\office\WordForms\" & Me.mMain.Pages(mMain.Value).Controls(0).Column(4)
        Case Is = "PDF"
            sPath = System.PrivateProfileString("", "HKEY_CLASSES_ROOT\acrobat\DefaultIcon", "")
            Shell sPath & " """ & Me.mMain.Pages(mMain.Value).Controls(0).Column(5) & """", vbMaximizedFocus
    End Select


    The second Case condition is the one I am having an issue with. sPath contains the path to Adobe Acrobat, and indeed Acrobat does launch. The result of the Column(5) value is in fact an HTTP location. What follows is what the Shell command attempts to execute:

    C:\Program Files (x86)\Adobe\Acrobat 9.0\Acrobat\Acrobat.exe "http://www.mnd.uscourts.gov/FORMS/Clerks_Office/CivilCoverSheet-JS044.pdf"

    I get an error message from Acrobat saying the file and/or location could not be found. It is in fact there, you can look for yourself, it's a publicly accessible file. At first I didn't quote the location value, but after getting the error message (the same one), I tried that too, without luck.

    My goal is to simply open the PDF. I have tried using Start...PDF, but that opens a shell window, opens IE, and then ultimately the PDF. A but kludgey I'd say.

    Ideas? Thoughts?


    Facebook: Zamdrist
    Roleplaying: Elliquiy
    Tuesday, September 27, 2011 9:54 PM

Answers

  • Hi Zamdrist

    Mmmm. If this is a user-specific setting and your environment security allows it, perhaps you can change this from within your code? I would assume it's a fairly straight-forward Registry setting - you just have to track it down.

    Word has the PrivateProfileString method that let's you change just about any Registry entry, as long as you, as a user, are allowed that kind of access.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Liliane Teng Thursday, October 6, 2011 9:02 AM
    Wednesday, September 28, 2011 4:49 PM
    Moderator

All replies

  • Have you tried asking this on an Adobe Acrobat support site? I'd think the Adobe folks would best know what might be wrong.

    Does the command line you're trying to execute work if you do it from within a Command window ("DOS window")?


    Cindy Meister, VSTO/Word MVP
    Wednesday, September 28, 2011 9:35 AM
    Moderator
  • Thanks Cindy, I may end up having to do that.

    The line of code in question is the Shell command. If I do the following, it works:

     

    Shell "cmd /c start """ & sPath & """ " & Me.mMain.Pages(mMain.Value).Controls(0).Column(5), vbMaximizedFocus

    And of course if in Acrobat I go File/Open and past in the URL address of the PDF it opens too. So what I am attempting should be possible. I was just trying to avoid the command window, start, etc. On my machine at least, it opens the PDF via IE, rather than Acrobat.

    Thanks

    Edit: If I turn off view in browser setting in Acrobat, Acrobat launches rather than IE. Our user environment is such that this setting could be set either way, from person to person. This isn't unexpected, and will have to suffice I guess.


    Facebook: Zamdrist
    Roleplaying: Elliquiy
    • Edited by ITMn0403 Wednesday, September 28, 2011 2:50 PM
    Wednesday, September 28, 2011 2:44 PM
  • Hi Zamdrist

    Mmmm. If this is a user-specific setting and your environment security allows it, perhaps you can change this from within your code? I would assume it's a fairly straight-forward Registry setting - you just have to track it down.

    Word has the PrivateProfileString method that let's you change just about any Registry entry, as long as you, as a user, are allowed that kind of access.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Liliane Teng Thursday, October 6, 2011 9:02 AM
    Wednesday, September 28, 2011 4:49 PM
    Moderator
  • Cindy, yes I am sure it is a registry setting. No matter though, different people here have it set various ways depending on their needs. But whether it opens in IE or Acrobat shouldn't matter too much.

    Thank you


    Facebook: Zamdrist
    Roleplaying: Elliquiy
    Wednesday, September 28, 2011 5:02 PM
  • Hi Zamdrist,

    Based on your last reply, I understand you have no matters. I closed this thread by marking Cindy's helpful suggestion as answer. Thanks for your understanding.

    If I misunderstood, please feel free to let us know.

    Have a nice day.

    Best regards


    Liliane Teng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, October 6, 2011 9:05 AM