Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50068

Using a wildcard in path (not filename) with Dir function

$
0
0
Hello,

I need to access a directory which consists of a name and a code. I have a file in which the codes always match with the code in the directory-name, but not the names in the directory-name, hence I cannot use the name to access the directory.
The directories look like this:\\Map\map\Name - code\map
For instance: C:\map1\map2\map3\Grontmij - NL0010200358\2013
In that directory I just need to open the excel file which is there, but I can't find a way to get there unless I have the exact directory, which keeps changing.


Code:

Sub Positiechecker()

Const strPath As String = "C:\map1\map2\map3\"
Dim strFile As String
ISINcode = "NL0010200358"
FolderName = Format(Date, "yyyy")
strFile = dir(strPath & "*" & ISINcode & "\" & FolderName & "\")

Workbooks.Open Filename:=strFile & "*.xls"

End Sub


This does not work, it seems to me the wildcard is not accepted in the path of the Dir() function, I have searched this forum, several others, used Google, checked the VBA reference sheet, but couldn't find the answer.

For those interested:
I have a file in which people have a reported a number of shares. In another file I have the correct number of shares. Stocks have a unique code, the ISIN. So, I have to check in file number 1 which ISIN it's about, then go to the correct directory in which file with the correct number of shares resides, open the excel file there, do the check and report if the number of shares is correct or not. These steps I can probably figure out myself, but accessing the correct directory is driving me nuts. Hopefully someone can help me! :)

Thanks in advance!

Maarten

ps, I can't figure out how you guys get those nice coloring in the code :(

Viewing all articles
Browse latest Browse all 50068

Trending Articles