+ Reply to Thread
Results 1 to 10 of 10

What's this sentence use: " sFil = Dir"?

  1. #1
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    95

    What's this sentence use: " sFil = Dir"?

    The sentence
    Please Login or Register  to view this content.
    at the end of the code below, what is its role?

    Please Login or Register  to view this content.
    Thanks!!

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: What's this sentence use: " sFil = Dir"?

    It calling the Dir again.

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: What's this sentence use: " sFil = Dir"?

    Earlier in the code was this line:
    Please Login or Register  to view this content.
    That set the DIR parameters and the first filename was collected and stored I the sFil string variable.

    Later, the shorter version you noted:
    Please Login or Register  to view this content.
    ..effectively calls the same code from above again, the same parameters, but collects the NEXT filename in the same folder. That loop continues each time until all the matching filenames have been collected once. After that the code exits.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    95

    Re: What's this sentence use: " sFil = Dir"?

    But how does computer know to collect next filename? There is no sentence like "i=i+1" I already know.

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: What's this sentence use: " sFil = Dir"?

    Do while is a loop as I=I+1 is.

  6. #6
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    95

    Re: What's this sentence use: " sFil = Dir"?

    Thank you for your explanation. But still a little bit confused. I checked the example in Help.
    Please Login or Register  to view this content.
    This is a loop with "counter = counter + 1 " as well. Why the previous code without "+1"?

  7. #7
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: What's this sentence use: " sFil = Dir"?

    sFil = Dir(sPath & "*.xls")
    sets sFil as all of the files in the diectory

    Do While sFil <> ""
    Means keep looping until the file name (sFil) is empty (do while not empty)
    You should hit F5, because chances are I've edited this post at least 5 times.
    Example of Array Formulas
    Quote Originally Posted by Jacc View Post
    Sorry, your description makes no sense. I just made some formula that looks interesting cause I had nothing else to do.
    Click the * below on any post that helped you.

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: What's this sentence use: " sFil = Dir"?

    It's a VBA thing, that original command simply means "get the first filename in the given path", and when you make the same call a second time using the shorter syntax, it simply means "get the NEXT filename from the same path". You can use the call over and over and each time it will get the NEXT filename until there are no more filenames.

    Just trust that's what it means, that's what it does, and use it.

  9. #9
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    95

    Re: What's this sentence use: " sFil = Dir"?

    Is it because: for "counter = counter + 1", computer doesn't know how many to add, then we have to tell '+1'. While for Files in one folder, the only way is to open one by one, so we don't need to tell computer.

  10. #10
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    95

    Re: What's this sentence use: " sFil = Dir"?

    Ok! I think I have understood much more. Maybe I thought too much. Thankyou all guys!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 4
    Last Post: 11-17-2013, 12:05 PM
  2. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  3. [SOLVED] Removing ".", "?" or "!" from last word of sentence and replacing it later in vba.
    By staggers47 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-16-2013, 07:20 AM
  4. Replies: 1
    Last Post: 01-05-2013, 03:31 PM
  5. Adding Commas into an "Equation Sentence"
    By sighlent1 in forum Excel General
    Replies: 3
    Last Post: 05-17-2011, 04:50 PM

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