check if folder exist with wildcards

BRB1983

Board Regular
Joined
Aug 29, 2019
Messages
61
I would like to use a wildcard to check if a folder exist. i have tried the following: "C:\Users\*\Desktop\New folder"
"C:\Users" & "*" & "\Desktop\New folder"
"C:\Users\ + "*" + "\Desktop\New folder"
i get, "bad file name or number." is there a way to do this?

Code:
Sub TestForDir()Dim strDir As String
    strDir = "C:\Users\*\Desktop\New folder\"
    
    If Dir(strDir, vbDirectory) = "" Then
        MkDir strDir
    Else
        MsgBox "Directory exists."
    End If
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I doubt that is possible. You will need to loop through all the subfolders under C:\Users\ and test if C:\Users\subfolder\Desktop\New folder\ exists and set a flag or count in the loop.

Unless you have Administrator rights over the PC you won't be able to access anyone else's profile under C:\Users\
 
Last edited:
Upvote 0
Are you trying to test if the folder exists on the current user's desktop?
 
Upvote 0
yes on the current user desktop. Also sharing the excel with one other user. so i need it to create a folder on desktop or in documents if folder don't exist. "C:\Users\bbonin\Desktop\New folder" this works on mine, but need it to work on a second desktop as well.
 
Upvote 0
You can get the desktop path with:

Code:
createobject("WScript.Shell").specialfolders("Desktop")

So:

Code:
strDir = createobject("WScript.Shell").specialfolders("Desktop") & "\New folder\"
    
    If Dir(strDir, vbDirectory) = "" Then
        MkDir strDir
    Else
        MsgBox "Directory exists."
    End If
 
Upvote 0

Forum statistics

Threads
1,213,544
Messages
6,114,249
Members
448,556
Latest member
peterhess2002

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top