Run-Time error 13 on a FileOpen command

W

Willibrord Koot

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.
 
J

Jim Cone

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
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
 
W

Willibrord Koot

Jim,

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top