VBA Dir function not working on Excel 2010

vba dir subfolders
vba dir returns empty string
dir function vba
vba dir loop
vba dir multiple files
vba directory listing
vba dir recursive
vba get folder names in directory

I mapped an intranet location using the File Explorer. i.e. mapped http://intranet.XXXXXXX.com/mydir/ to M:\

I'm using the Dir function to test if a file is present in that location:

 Dim FileExists as Boolean

 FileExists = Dir("M:\myfile") <> ""

 If FileExists Then MsgBox "File found in M:"

I run that macro on Excel 2007 and it Works Fine. When I run it on Excel 2010 though, Dir("M:\myfile") always returns "", even if the file is present in the specified location. I can´t find a solution that will work on both Excel versions. Any ideas?

You may add file extension as a wildcard character at the end of filepath. I gave a try in excel 2010 and it worked for me.

  Dim FileExists As Boolean
    FileExists = Dir("D:\myfile" & "*.txt") <> ""

    If FileExists Then MsgBox "File found in M:"

DIR function not working in EXCEL 2010, VBA code, In troubleshooting an issue this week I discovered these issues are in conjunction with the DIR function, used to provide a selectable "LIST of . For some reason my Dir function won't find any file even if the file does exist. I am not totally familiar with VBA so i may perhaps be missing some sort of reference to perform the Dir function, but I can't find anything online that tells me I need to. All the examples and forums use Dir just like I do, but I can't get mine to work.

I found that if I use the full network name, it works first go. This wasn't just in VBA, but also some shortcuts also - they returned "File could not be found".

Changing from the mapped shortcut, e.g.


to the full mapped path, e.g.


Fixed the problem

VBA DIR Function - An Easy Explanation with , Excel Facts. Can you AutoAverage in Excel? Click here to reveal answer. DIR function not working in EXCEL 2010, VBA code My shop upgraded to Win7-OFFICE 2010 this summer and one of our EXCEL apps has a lot of VBA code attached (legacy from EXCEL 2000 thru 2007), and some staff are experiencing some issues.

Here is how to use FSO to do what you want:

Option Explicit

Function test_it()
    'Test the Function - must pass the file path and name
    Debug.Print Does_File_Exist("C:\temp\form1.txt")
End Function

Private Function Does_File_Exist(sFullPath) As Boolean
' Will return True or False if file exists.
' Provide the fully qualified path and file name.
' You can disable the MsgBox displays after testing

Dim oFs         As New FileSystemObject
Dim oFile       As File

    Set oFs = New FileSystemObject
    If oFs.FileExists(sFullPath) Then
        Does_File_Exist = True
        MsgBox "Found file: " & sFullPath
        Does_File_Exist = False
        MsgBox "File not found: " & sFullPath
    End If

    Set oFs = Nothing
End Function

Dir function is not working, This website would not exist without the advertisements we display and your kind donations. If you are unable to support us by viewing our advertisements, please​  VBA - Dir function not working. 2010 Platform Windows, MacOS SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called

MS Excel: How to use the DIR Function (VBA), Note that these characters do not work as wildcards on the Macintosh. VBA Dir Function Examples. Example 1 - Search for a File. ' Find the file "C  However, you can't call the Dir function recursively. Calling Dir with the vbDirectory attribute does not continually return subdirectories. With Excel for Mac 2016, the initial Dir function call will succeed. Subsequent calls to iterate through the specified directory will cause an error, however.

VBA DIR Function, Here, ' pathname ' specifies the location of a file, folder or a directory. If the ' pathname ' is not found, DIR returns a string of zero length. ' attributes ' is an optional  The DIR function is a built-in function in Excel that is categorized as a File/Directory Function. It can be used as a VBA function (VBA) in Excel. As a VBA function, you can use this function in macro code that is entered through the Microsoft Visual Basic Editor.

VBA DIR Function - How to Use in Excel, Today I'm working to adapt an old code that I had into a project that I'm working on but for some reason the dir function is not working because it's inside the ISS_Templates folder there is a bunch of excel files so the default  However, you can't call the Dir function recursively. Calling Dir with the vbDirectory attribute does not continually return subdirectories. Tip Because file names are retrieved in no particular order, you may want to store returned file names in an array, and then sort the array. Example