[RESOLVED] ShellExecute PDF "file already open" error-VBForums
Results 1 to 4 of 4

Thread: [RESOLVED] ShellExecute PDF "file already open" error

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    44

    Resolved [RESOLVED] ShellExecute PDF "file already open" error

    Greetings,

    Running Vista and VB6:

    I'm using shellexecute to launch files with their associated application. This works for all files except PDF files. With PDF files, I can launch a given file one time successfully, then any subsequent attempts to launch that same file results in the following:

    * Adobe Reader opens
    * Adobe Reader reports the following error:
    "There was an error opening this document. This file is already open or in use by another application."

    I can open the file by double-clicking on it from Windows Explorer.

    After some time passes, I may or may not be able to successfully launch this same PDF file from my app. Restarting my app has no effect on this behavior.

    Here is the code I'm using:

    Code:
    Private 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
    
    Const SW_SHOWNORMAL as Long = 1
    
    sAddr = sAddr & vbNullChar
    lHndl = ShellExecute(mf.hwnd, "open", sAddr, "", "", SW_SHOWNORMAL)
    Any clues would be much appreciated.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,829

    Re: ShellExecute PDF "file already open" error

    i tested your code it had no problem, on my machine opened the same file many times, if the file was still open, it activated the adobe reader window, are you writing the pdf before opening?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,334

    Re: ShellExecute PDF "file already open" error

    I just tested your code as well and has no difficulties, so something else has to be going on with something other than the code that you posted.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    44

    Re: ShellExecute PDF "file already open" error

    Thanks all.

    Apparently a call to ShellExecute will return before the program being called opens the file being passed to it, at least with PDF files. My program was calling a quick file open binary shared after the ShellExecute command under the assumption that Adobe had already launched.

    Resolved.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.