+ Reply to Thread
Results 1 to 12 of 12

dir function returns not always implicit extension

  1. #1
    Registered User
    Join Date
    06-18-2013
    Location
    antwerp
    MS-Off Ver
    Excel 2010
    Posts
    7

    dir function returns not always implicit extension

    Hello,

    excel 2010 works with implicit extensions (.xlsx)
    When I run a macro on my PC,
    the following
    <<
    fName = Dir(wsDir & wsFile & "*")
    Do While Len(fName)
    >>
    gives back the required files with implicit extension .xlsx.

    Unfortunately when a user runs the macro it does not find the required files.


    When I change it to
    <<
    fName = Dir(wsDir & wsFile & ".*")
    Do While Len(fName)
    >>
    it does work on the PC of the user, but not on my PC.


    Is there a general setting which provokes this ?

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: dir function returns not always implicit extension

    I don't know the content of wsDir and wsFile
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    06-18-2013
    Location
    antwerp
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: dir function returns not always implicit extension

    it is a folder which contains excel 2010 documents (so with implicit file extension .xlsx)

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: dir function returns not always implicit extension

    I can not help you if you don't want help me

  5. #5
    Registered User
    Join Date
    06-18-2013
    Location
    antwerp
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: dir function returns not always implicit extension

    I try to explain with an example

    So wsDir contains the netwerk path and wsFile contains the name without extentions.
    To avoid avoid testing on full extension .xls or .xlsx or ..., I used the syntax Dir(wsDir & wsFile & ".*")

    On my PC it did not work. It only works when I change to "*", then it returns all the documents which are in the new windows7 explorer, which works with implicit extension (so you do not see the extension), whereas in the old windowsxp explorer all documents were with an explicit extention..

    But on the PC of a user which also has windows7, it only works with syntax Dir(wsDir & wsFile & ".*")

    => Therefor my question what makes that when you run a macro on a PC you have to use syntax "Dir(wsDir & wsFile & ".*")" and on other PC you have to use "Dir(wsDir & wsFile & "*") and this for the same documents both PC's already with windows7

  6. #6
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: dir function returns not always implicit extension

    Hi Bart,

    why not use this :
    Please Login or Register  to view this content.
    Please click the * below if this helps

  7. #7
    Registered User
    Join Date
    06-18-2013
    Location
    antwerp
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: dir function returns not always implicit extension

    Yes, this could be an alternative way to solve this, search through all the files in the folder and use the one which has a name to the one I need. I could also test if nothing found with the first syntax (".*), use then the second one ("*")

    But I want to understand why the macro reacts differently

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: dir function returns not always implicit extension

    explorer in both windows 7 and xp had the option to show or hide extensions-by default they are hidden in both. perhaps one machine has them hidden and the other does not
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  9. #9
    Registered User
    Join Date
    06-18-2013
    Location
    antwerp
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: dir function returns not always implicit extension

    Thanks for that.
    I didn't know that it aleady existed in windows xp. So probably there the default value was with explicit extension, and in windows7 with implicit.

    It stays still a mystery to me because for both PC's it had the same default value, so implicit extension.

    And to make it stranger, now the macro run on my PC reacts in the same way as the user so with ".*".

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: dir function returns not always implicit extension

    Hello bartw,

    The Dir function in VBA will return all files in a folder if no file extension is given in the first call of Dir. To return files of of a given type, you should always include the file extension.

    Here is an example of a properly formed Dir statement to return all xlsx files in the folder wsDir.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  11. #11
    Registered User
    Join Date
    06-18-2013
    Location
    antwerp
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: dir function returns not always implicit extension

    Hi, I'm working with a name (cf. Filename in the syntax), so my purpose was to make it work for files of type .xls / .xlsx or whatever extension may be used in the future.

    So the result was that I do retrieve normally 1 file (although for some time I did not retrieve any)

    I still do not understand, but probably it has more to do with windows settings/what is in your registry than with vba/excel so I'll close this

  12. #12
    Registered User
    Join Date
    06-18-2013
    Location
    antwerp
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: dir function returns not always implicit extension

    [solved] ;;;;;;;;;;;;;

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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