Greetings,
I am a little new to vba, and I recorded a macro to open a file in the format S1T1C1. S=subject#, T=trial# and C=condition#. I then modified it to open in a loop by trial number and move it to a new sheet in book1. Everything works fine except when there are more than 9 files in the containing folder.
For example I have 12 trials for subject 1 and when it opens the first trial it opens S1T10C1 instead of S1T1C1. The problem lies with the instruction to ignore anything in the condition part of the name since the conditions are selected at random and will be different every time.
Workbooks.OpenText Filename:="C:\Users\marcus\Desktop\Balance\S" & subject & "T" & i & "*" & ".VFC"
Is there any way to differentiate between 1 and 10 while still ignoring anything that comes after the trial number?
Thank you for any help that you can provide,
Marcus
Please see the entire "for" loop below.
For i = 1 To trials
Workbooks.OpenText Filename:="C:\Users\marcus\Desktop\Balance\S" & subject & "T" & i & "*" & ".VFC", _
Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1)), TrailingMinusNumbers:=True
name = ActiveSheet.name
Windows(name & ".VFC").Activate
Sheets(name).Select
Sheets(name).Move Before:=Workbooks("Book1").Sheets(i)
Bookmarks