Create a folder

  • Thread starter Thread starter Ray
  • Start date Start date
R

Ray

I would like to do the following;
If the folder "Morning Reports" does not exist on the desktop, then create
it.

Any ideas?
 
It is the first part that is giving me trouble
If the folder "Morning Reports" does not exist on the desktop
 
if the folder doesn't exist, MkDir will create it. if it does exist, MkDir
will generate error code 75. you can write an error handler to take care of
that, or add On Error Resume Next to the beginning of the procedure, to
ignore all errors in the procedure.

hth
 
Ray said:
I would like to do the following;
If the folder "Morning Reports" does not exist on the desktop, then create
it.

Any ideas?

To get the Desktop's folder location requires a little api work. Paste this
code into a new module:

''' CODE START '''
Private Type SHITEMID
cb As Long
abID As Byte
End Type
'
Private Type ITEMIDLIST
mkid As SHITEMID
End Type
'
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _
(ByVal hWndOwner As Long, ByVal nFolder As Long, _
pidl As ITEMIDLIST) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, ByVal pszPath As String) As Long

Public Function DesktopFolder() As String
Dim IDL As ITEMIDLIST
'
If SHGetSpecialFolderLocation(100&, 0&, IDL) = 0 Then
Path$ = Space$(512)
SHGetPathFromIDList ByVal IDL.mkid.cb, ByVal Path$
DesktopFolder = Left$(Path$, Instr(1, Path$, Chr$(0)) - 1)
End If
End Function
''' CODE END '''

Then, when you need the path simply type DesktopFolder().

So, to fully answer your question:

strFolder = DesktopFolder() & "\Morning Reports"
If Dir$(strFolder, vbDirectory) = "" Then
MkDir strFolder
End If
 
Back
Top