kv2e
11-22-2010, 05:30 PM
My VBA script in a word template is checking to see if a folder exists, then if it doesn't, creates the folder and (not shown) saves the word doc.
It works perfectly - unless the folder exists but is empty, in which case it returns an error (apparently, the If Dir statement thinks the folder doesn't exist, if empty). I tried removing the trailing \ in the FolderPath with the same result.
Here is my code:
Dim Uname As String
Dim FolderPath As String
Uname = Environ("USERNAME")
FolderPath = "C:\Documents and Settings\" & Uname _
& "\My Documents\Recipes\"
' Check if Recipe folder exists, if not create it.
If Dir(FolderPath) = "" Then
MkDir FolderPath
End If
Any suggestions??
Thanks!
Bill (kv2e)
It works perfectly - unless the folder exists but is empty, in which case it returns an error (apparently, the If Dir statement thinks the folder doesn't exist, if empty). I tried removing the trailing \ in the FolderPath with the same result.
Here is my code:
Dim Uname As String
Dim FolderPath As String
Uname = Environ("USERNAME")
FolderPath = "C:\Documents and Settings\" & Uname _
& "\My Documents\Recipes\"
' Check if Recipe folder exists, if not create it.
If Dir(FolderPath) = "" Then
MkDir FolderPath
End If
Any suggestions??
Thanks!
Bill (kv2e)