+ Reply to Thread
Results 1 to 3 of 3

opening files in a loop with "1" or "10" in the name

Hybrid View

wireboy0011 opening files in a loop with... 12-08-2008, 01:14 PM
royUK Your post does not comply... 12-08-2008, 01:18 PM
wireboy0011 Thank you, sorry about that. 12-08-2008, 01:27 PM
  1. #1
    Registered User
    Join Date
    11-25-2008
    Location
    USA
    Posts
    5

    opening files in a loop with "1" or "10" in the name

    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)
    Last edited by royUK; 12-08-2008 at 01:18 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Your post does not comply with Rule 3 of our Forum Rules. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here http://www.excelforum.com/misc.php?do=bbcode#code

    I will add them this time
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    11-25-2008
    Location
    USA
    Posts
    5
    Thank you, sorry about that.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1