Link to home
Start Free TrialLog in
Avatar of Anne Troy
Anne TroyFlag for United States of America

asked on

Error on make folder Excel VBA

If Len(Dir("Report " & Format(Date, "yyyymmdd"))) = 0 Then 
    MkDir "Report " & Format(Date, "yyyymmdd") 
Else 
    MsgBox "You already ran today's reports and need to delete the folder before running them again." 
    Exit Sub 

Open in new window


I just get a Path/File access error on the MkDir line of code instead of getting the message box.
I have tried moving the lines around, too. Anybody know what I'm doing wrong?
Avatar of Ramesh V
Ramesh V

Try this

Sub create()
    If Len(Dir("Report " & Format(Date, "yyyymmdd"))) = 0 Then
        MkDir "C:\Users\rvatta\Desktop\Reports" & "\" & "Report " & Format(Date, "yyyymmdd")
    Else
        MsgBox "You already ran today's reports and need to delete the folder before running them again."
        Exit Sub
    End If
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Ramesh V
Ramesh V

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Ejgil Hedegaard
Ejgil Hedegaard
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Anne Troy

ASKER

It appears I needed BOTH.

Sub create()
If Len(Dir("Report " & Format(Date, "yyyymmdd"), vbDirectory)) = 0 Then
        MkDir ThisWorkbook.Path & "\" & "Report " & Format(Date, "yyyymmdd")
    Else
        MsgBox "You already ran today's reports and need to delete the folder before running them again."
        Exit Sub
    End If
End Sub

Open in new window


Thanks so much!