+ Reply to Thread
Results 1 to 3 of 3

Run-Time error 13 on a FileOpen command

  1. #1
    Registered User
    Join Date
    04-07-2005
    Posts
    6

    Run-Time error 13 on a FileOpen command

    I have created a macro that uses GetOpenFilename to ask the user for an Excel file to open and then uses FileOpen to actually open the file.

    On my own machine (Excel 2003), this macro works fine, but on the machine of a colleague (Excel 2002, SP3), the macro returns a Run-Time error 13 'Type mismatch' error, although it does open the Excel file (but the macro halts). I do have an 'On Error resume next' command included in the macro, but it still halts.

    In the macro, I am using the GetOpenFilename / FileOpen routine twice: once to select and open a .txt file (works fine on both machines) and once to select and open a .xls file (works on mine, aborts on my colleague's machine).

    Below is the code I am using:

    For the txt file:

    ' Get correct filename to open
    FileToOpen = Application.GetOpenFilename("All Files, (*.txt)")
    If FileToOpen = False Then
    'Nothing selected
    Exit Sub
    End If

    ' Open journal file
    Workbooks.OpenText Filename:=FileToOpen, _
    Origin:=437, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array( _
    Array(0, 1), Array(2, 1), Array(7, 1), Array(11, 1), Array(15, 1), Array(19, 1), Array(27, 1), Array(41, 1 _
    ), Array(53, 1)), TrailingMinusNumbers:=True

    For the Excel file:
    ' Get correct filename to open
    FileToOpen = Application.GetOpenFilename("All Files, (*.xls)")
    If FileToOpen = False Then
    'Nothing selected
    Exit Sub
    End If

    ' Open LH Template file
    Workbooks.Open Filename:=FileToOpen

    Any help would be highly appreciated.

  2. #2
    Jim Cone
    Guest

    Re: Run-Time error 13 on a FileOpen command

    Willibrord,

    In XL2002 the Origin argument for the OpenText method can only be...
    1, 2, or 3. (Mac, Windows, DOS).
    Change it to correct value or just omit the argument.

    Regards,
    Jim Cone
    San Francisco, USA


    "Willibrord Koot"
    wrote in message
    news:[email protected]
    I have created a macro that uses GetOpenFilename to ask the user for an
    Excel file to open and then uses FileOpen to actually open the file.
    On my own machine (Excel 2003), this macro works fine, but on the
    machine of a colleague (Excel 2002, SP3), the macro returns a Run-Time
    error 13 'Type mismatch' error, although it does open the Excel file
    (but the macro halts). I do have an 'On Error resume next' command
    included in the macro, but it still halts.
    In the macro, I am using the GetOpenFilename / FileOpen routine twice:
    once to select and open a .txt file (works fine on both machines) and
    once to select and open a .xls file (works on mine, aborts on my
    colleague's machine).
    Below is the code I am using:
    For the txt file:

    ' Get correct filename to open
    FileToOpen = Application.GetOpenFilename("All Files, (*.txt)")
    If FileToOpen = False Then
    'Nothing selected
    Exit Sub
    End If

    ' Open journal file
    Workbooks.OpenText Filename:=FileToOpen, _
    Origin:=437, StartRow:=1, DataType:=xlFixedWidth,
    FieldInfo:=Array( _
    Array(0, 1), Array(2, 1), Array(7, 1), Array(11, 1), Array(15,
    1), Array(19, 1), Array(27, 1), Array(41, 1 _
    ), Array(53, 1)), TrailingMinusNumbers:=True

    For the Excel file:
    ' Get correct filename to open
    FileToOpen = Application.GetOpenFilename("All Files, (*.xls)")
    If FileToOpen = False Then
    'Nothing selected
    Exit Sub
    End If

    ' Open LH Template file
    Workbooks.Open Filename:=FileToOpen

    Any help would be highly appreciated.--
    Willibrord Koot


  3. #3
    Registered User
    Join Date
    04-07-2005
    Posts
    6

    FileOpen Command

    Jim,

    The OpenText doesn't generate an error, so there is no need changing that.

    However, in the mean time I have found that the error is actually being caused by the file that is being opened. Unfortunately, that's a file created by a corporate team and the macros are protected, so I will have to get back to the corporate team.

+ Reply to Thread

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