Creating folder and subfolders

Cablek

Board Regular
Joined
Nov 22, 2017
Messages
51
I have a script that creates a folder (if non already exists) then saves an excel file in this folder and it works great but a new request had come up where I need to create 2 sub folders with in this new folder... 1 called "drawings" and one called "Obsolete"

this is my present code:


Private Sub CommandButton1_Click()
Dim Pth As String
Dim Filename1 As String
Dim Filename2 As String
Pth = "O:\Customer Drawings" & Range("B3").Value
Filename1 = Range("C3").Value
Filename2 = Range("D3").Value
If Dir(Pth, vbDirectory) = "" Then MkDir (Pth)
ActiveWorkbook.SaveAs Filename:=Pth & "" & Filename1 & "- Rev" & Filename2 & "(" & Format(Date, "dd-mm-yyyy") & ")" & ".xlsm", FileFormat:=52
End Sub


Private Sub Worksheet_change(ByVal Target As Excel.Range)
If Target.Column = 2 And Target.Row >= 3 And Target.Row <= 10000 Then
Target.Offset(0, -1) = Date
End If
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Code:
Private Sub CommandButton1_Click()
Dim Pth As String
Dim Filename1 As String
Dim Filename2 As String
    Pth = "C:\Customer Drawings" & Range("B3").Value
    Filename1 = Range("C3").Value
    Filename2 = Range("D3").Value
    If Dir(Pth, vbDirectory) = "" Then
        MkDir (Pth)
        MkDir (Pth & "\Drawings")
        MkDir (Pth & "\Obsolete")
    End If
    ActiveWorkbook.SaveAs Filename:=Pth & "" & Filename1 & "- Rev" & Filename2 & "(" & Format(Date, "dd-mm-yyyy") & ")" & ".xlsm", FileFormat:=52
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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