I am trying to open two csv files, the first one starts with ca_ewor and the second starts with ca_pr. If I run the following commands...
cf gives me the first file's name then cf gives me the second file's name.
If I open the first file before getting the name of the second file then I get a, "Run-time error '9': Subscript out of range"
I know I could use two different variables and I am sure there are other ways around this but can someone tell me why this is happening.
OTHER FACTS
Each file has a different number of columns and I do expect the number of columns to change if this is related.
I am using Excel 2010
Code:
Dim cf As String
cf = Dir(Worksheets("Sheet1").Cells(1, 2) & "\ca_ewor*.csv")
cf = Dir(Worksheets("Sheet1").Cells(1, 2) & "\ca_pr*.csv")
cf gives me the first file's name then cf gives me the second file's name.
If I open the first file before getting the name of the second file then I get a, "Run-time error '9': Subscript out of range"
Code:
Dim cf As String
cf = Dir(Worksheets("Sheet1").Cells(1, 2) & "\ca_ewor*.csv")
Workbooks.OpenText Filename:=cf, Origin:=65001, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, _
Tab:=False, Semicolon:=False, Comma:=True, _
Space:=False, Other:=False 'Open the Cummins-Allison Problem Report
cf = Dir(Worksheets("Sheet1").Cells(1, 2) & "\ca_pr*.csv")
I know I could use two different variables and I am sure there are other ways around this but can someone tell me why this is happening.
OTHER FACTS
Each file has a different number of columns and I do expect the number of columns to change if this is related.
I am using Excel 2010
Last edited: