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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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