I have the following code :

VB Code:
  1. Function Vals(File As String, Prob As Integer) As Variant
  2. Set oXLApp = New Excel.Application
  3.   oXLApp.Visible = True
  4.  
  5.  oXLApp.Workbooks.OpenText FileName:=File, _
  6.         Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
  7.         xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, Semicolon:=False, _
  8.         Comma:=False, Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), _
  9.         Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1)), _
  10.         TrailingMinusNumbers:=True
  11.  
  12.  Set oXLBook = oXLApp.Workbooks(File)
  13.  Set oXLSheet = oXLBook.Worksheets(1)
  14. .....
  15. Vals = ...
  16.  
  17. End Function


I get a subscript out of range error at the
Set oXLBook = oXLApp.Workbooks(File)
statement - why ?

I've checked that File does contain the correct string.

If I change the statement to :
Set oXLBook = oXLApp.Workbooks.Open(File)
everything works fine, but now I don't parse the text file correctly (It seems like it assumes default settings that are different from those that I specify in the OpenText statement).

Thanks,