M
Marchand
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 =
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 =