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