Answer: This can be done with a formula that utilizes a combination of the DIR function, IF function, and LEN function. Later it recursively calls the ‚ÄėEnlist_Directories‚Äô function to retrieve the file names. Example 8: Use the concept of the above two examples and write a VBA code that enlists all the files inside a current location and its subfolder. Last edited by willknapp; 07-02-2013 at 09:27 AM.
If the directory is not present then create that directory. vbReadOnly Specifies read-only files as well as files with no attributes. vbAlias Specifies Files having different names. My question is that, if it is a bad file name, why does it cause an error rather than return an empty string?
Here is the code, please tell me if you can see what I am doing wrong: Public Function Get_File() as string Dim filePath As String ChDir ("..") filePath = CurDir 'Goes If (GetAttr(Path & FirstDir) And vbDirectory) = vbDirectory Then ActiveSheet.Cells(ctr, 1).Value = Path & FirstDir ctr = ctr + 1 End If FirstDir = Dir()¬†¬† ' Getting next entry. I get an error on the first line Option Compare Database ("expected Text or Binary"). I am still, however, unable to figure out why I couldn't trap the runtime error, but that's not causing as much of a problem anymore.
All the examples and forums use Dir just like I do, but I can't get mine to work. Seems to me that your code is not for VBA for Excel, is it? –user3366899 Mar 5 '14 at 15:04 add a comment| Your Answer draft saved draft discarded Sign more stack exchange communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed ActiveSheet.Cells(ctr, 1).Value = Path & File ctr = ctr + 1 File = Dir()¬†¬† ' Getting next entry.
I cannot recreate it reliably, and when I run the offending code in the Immediate window - while the VBA is in break mode - using the literal values of the