Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivot Table Error Message - "Command Text not set for command obje Jeff Divian Excel Discussion (Misc queries) 0 November 7th 07 10:26 PM
Run Time Error for Vlookup & Match command Syed Haider Ali[_23_] Excel Programming 1 September 19th 05 06:15 PM
fileopen A-Design Excel Programming 4 November 22nd 04 05:52 PM
Command Button run-time error Dominique Feteau Excel Programming 1 June 29th 04 02:57 AM
Run-time error on command button Phil Hageman[_3_] Excel Programming 4 November 4th 03 08:06 PM


All times are GMT +1. The time now is 03:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"