Thread: MkDir question
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Jim G Jim G is offline
external usenet poster
 
Posts: 132
Default MkDir question

Perfectly simple, thanks John
--
Jim


"john" wrote:

Try this code (use standard module) Declare Function must be at top of module.

Declare Function MakePath Lib "imagehlp.dll" Alias _
"MakeSureDirectoryPathExists" (ByVal lpPath As
String) As Long

Sub CreatePath()
MakeDir "C:\Invoices\Invoices\BackUp"
End Sub

Sub MakeDir(DirPath As String)

If Right(DirPath, 1) < "\" Then DirPath = DirPath & "\"

MakePath DirPath

End Sub
--
jb


"Jim G" wrote:

The following macro works and will eventurally be used in a Workbook Close
event. My question is why do I need to use MkDir twice to create a
subdirectory as C:\SubDir1\SubDir2. Is there an easier way to do this?

Private Sub TestSave()
'-----create a Backup

Dim BUpath1 As String
Dim BUpath2 As String
Dim BUname As String

BUpath1 = "C:\Invoices"
BUpath2 = "C:\Invoices\BackUp"
BUname = "Sub-Contract Invoice BACKUP TEST " & Format(Now, "dd-mmm-yy
h-mm-ss")

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Worksheets("Start").Activate
ThisWorkbook.Save

On Error Resume Next
If Dir(BUpath2) = "" Then
MkDir (BUpath1)
MkDir (BUpath2)
ActiveWorkbook.SaveCopyAs BUpath2 & "\" & BUname

MsgBox "A copy of the file has been saved as: " & BUpath & "\" & BUname
End If

With Application
.ScreenUpdating = True
.EnableEvents = True
End With

End Sub
--
Jim