Results 1 to 6 of 6

Open File problem using Shell command

Threaded View

  1. #1
    Registered User
    Join Date
    07-13-2010
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    5

    Open File problem using Shell command

    Hi,
    I succesfully use a VBA-program for starting up other applications,. i.e. other spreadsheets.
    Example:

    Sub ShellProg ()
    Dim ResStart As Variant
    Dim strPath, strFile, strShell, strName As String

    strPath = Worksheets("Standards").Cells(2, 2).Value
    strFile = Worksheets("Standards").Cells(9, 2).Value
    strShell = strPath + " " + strFile
    strName = "UserSheet1.xls"

    ResStart = Shell(strShell, 1)

    strPath = Worksheets("Standards").Cells(2, 2).Value
    strFile = Worksheets("Standards").Cells(10, 2).Value
    strShell = strPath + " " + strFile
    strName = "UserSheet2.xls"

    ResStart = Shell(strShell, 1)

    etc.
    This works beautifully.
    Now, I want to check whether a certain user file (UserSheet2.xls) has already been openend and I include before the Shell command:
    strName = "UserSheet2"
    If bFileOpen((strName)) Then
    Etc.

    Function bFileOpen(wbName As String) As Boolean
    Dim wb As Workbook
    'check each open workbook's name, in lower case, and set the function
    'to true if a match is found. If not match the function defaults to False
    For Each wb In Workbooks
    If LCase(wb.Name) = LCase(wbName) Then
    bFileOpen = True
    Exit Function
    End If
    Next
    End Function
    This check is unsuccessfull, even if UserSheet2.xls is definitively open. However, should I have started up manually my second worksheet UserSheet2.xls, not via ShellProg, then the same test is successful.

    So, there seems to be a difference between spreadsheets having been started up through a shell and the same spreadsheets having been started up manually by double clicking on the file name.
    Also, after my spreadsheets have been started up through the ProgShell program, I could delete ProgShell itself, but the same difference exists: the spreadsheets having been started by ProgShell act differently from the same spreadsheets having been started by hand, even though the starter program ProgShell has already gone.

    Can somebody explain this, please?

    Thanks in advance,

    Roel
    Last edited by roelvdh; 07-13-2010 at 04:02 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1