LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Excel 2010 crashes on Workbooks.Open for csv file -- sometimes

I'm trying to open a csv file within Excel as a workbook. In the good
old days the simple

Dim i As Integer
Dim iNumRetries As Integer
Dim wkbT As Workbook

' Explicitly initialize the return value
Set openCSVFile = Nothing

' Read how many times to try
iNumRetries = U_System.Range("rngNumCSVRetries").Value

' If you can't open it then try, try again -- up to the limit
'On Error Resume Next
For i = 1 To iNumRetries
Set wkbT = Workbooks.Open(psRawName) ', 0, True, 6, , True, ,
Chr(9))
If Not (wkbT Is Nothing) Then
Exit For
End If
Next

Set openCSVFile = wkbT

worked fine. And it still does, it I walk through the code (e.g. F8).
However if the macro is called from either the ribbon or the immediate
window, Excel crashes at the Workbooks.Open() statement. And 'crashes'
in the sense of the pop-ups "Microsoft Excel has stopped working ....
is trying to recover your information ..."

Changing the code to be much more explicit, i.e.

Workbooks.OpenText Filename:=psRawName, origin:=xlWindows,
StartRow:=1, _
DataType:=xlDelimited,
TextQualifier:=xlTextQualifierNone, ConsecutiveDelimiter:=False, _
Tab:=False, Semicolon:=False, Comma:=True,
Space:=False, Other:=False

results in the same behavior. The file being opened is a plain
vanilla, nothing special, no weird characters, comma delimited file.

So I'm stumped. Anyone know why F8-ing through the code works but
letting it run as a full macro fails? Even better, any ideas on how to
fix the issue?

= M =
 
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
Can't open workbook in excel 64 bit 2010 - but can in excel 2010 3 Darrell[_2_] Excel Programming 0 January 12th 10 08:53 PM
Excel crashes when I open the file, except..... MiNK Excel Programming 0 June 12th 08 02:32 PM
Excel 2007 crashes when I open a file with vba code Harrie Ribbers Excel Programming 10 October 18th 07 05:32 PM
workbooks.open function fails to open an existing excel file when used in ASP, but works in VB. san Excel Programming 1 January 3rd 06 03:22 AM
Excel 2003 Workbooks.Open with CorruptLoad=xlRepairFile fails on Excel 5.0/95 file due to Chart, with Error 1004 Method 'Open' of object 'Workbooks' failed Frank Jones Excel Programming 2 June 15th 04 03:21 AM


All times are GMT +1. The time now is 02:59 AM.

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

About Us

"It's about Microsoft Excel"