Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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. -- Willibrord Koot ------------------------------------------------------------------------ Willibrord Koot's Profile: http://www.excelforum.com/member.php...o&userid=21908 View this thread: http://www.excelforum.com/showthread...hreadid=472108 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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:Willibrord.Koot.1w6gad_1128092737.5228@excelf orum-nospam.com 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
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run-Time error 13 on a FileOpen command
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 -- Willibrord Koo ----------------------------------------------------------------------- Willibrord Koot's Profile: http://www.excelforum.com/member.php...fo&userid=2190 View this thread: http://www.excelforum.com/showthread.php?threadid=47210 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Pivot Table Error Message - "Command Text not set for command obje | Excel Discussion (Misc queries) | |||
Run Time Error for Vlookup & Match command | Excel Programming | |||
fileopen | Excel Programming | |||
Command Button run-time error | Excel Programming | |||
Run-time error on command button | Excel Programming |