MattCucco
MattCucco

Reputation: 133

Using Directories in Excel

I'm trying to get some data out of excel files. Never used excel before but I understand VB. So I have a file with a button my boss implemented as well as his code he used. Here is the code: enter image description here enter image description here

(you can see the "Get Data" button in there) My exact problem is that I don't know a lot about excel so if someone could help me figure out what is going on as well as figuring out how to correctly use directories that would be awesome! For more context when you click the button it gets all files in the directory and then the user clicks a file then excel follows a macro to get some data out of sed file.

Right now it returns nothing but there is 5 files in that directory?

Here is what the default directory looks like after edit: enter image description here And here is the files in my directory: enter image description here

Upvotes: 1

Views: 56

Answers (2)

dbmitch
dbmitch

Reputation: 5386

As @Tim Williams says ... Insert the back slash after the folder name

DirNow = Dir(Range("DefaultDirectory") + "\WFP*", vbDirectory)

EDIT

Basic troublseshooting

  1. Does it it compile? Looks like "UserFormDataa" - should maybe be "UserFormData"

  2. Add Debug.Print DirNow after it's set and show us the display

  3. If that's not right add line Debug.Print Range("DefaultDirectory") to makes sure range is defined properly

  4. Remove vbDirectory - unless you're going to handle processing files under the matching sub-folders

Upvotes: 1

Tim Williams
Tim Williams

Reputation: 166126

You are missing the terminal backslash on your default directory.

C:\Users\CUCCOMTT\Desktop\Excel Project\

Otherwise you're looking for files named

C:\Users\CUCCOMTT\Desktop\Excel ProjectWFP

Upvotes: 1

Related Questions