Macro/VBA Create new folder and save workbook as

NVRensburg

Board Regular
Joined
Jul 1, 2014
Messages
113
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I've tried a couple examples from other posts but no luck yet. Please could someone help me with a code :)

I have a workbook called "Subcontractor Spreadsheet". I want to create a macro that would create a new folder in location "J:\Alaska New Filing System (In Progress)\Tenders\Tenders by Project Number" named on the contents of cell B2 and then save the workbook as (save a copy in other words) filename in cell B3 and B2 (so I don't want to affect my master document.)
Thanking you in advance!
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try this:
VBA Code:
Public Sub Save_Workbook_Copy()

    Dim folder As String
    
    folder = "J:\Alaska New Filing System (In Progress)\Tenders\Tenders by Project Number\"
    
    CreateObject("WScript.Shell").Run "cmd /c mkdir " & Chr(34) & folder & Chr(34), vbMinimizedNoFocus, True
    
    With ThisWorkbook
        .SaveCopyAs folder & .ActiveSheet.Range("B3").Text & .ActiveSheet.Range("B2").Text & Mid(.FullName, InStrRev(.FullName, "."))
    End With
    
End Sub
 
Upvote 0
Thank you, this kind of works. It creates a copy of the spreadsheet in the folder "Tenders by Project Number" however it doesn't create a new folder in that folder. So I'm wanting it to create a new FOLDER in the folder "tenders by project number" and name that folder the text in cell B2 and then save that spreadsheet in that new folder.
 
Upvote 0
Sorry, I missed the B2 folder requirement. Try this:
VBA Code:
Public Sub Save_Workbook_Copy()

    Dim folder As String
    
    With ThisWorkbook
        folder = "J:\Alaska New Filing System (In Progress)\Tenders\Tenders by Project Number\" & .ActiveSheet.Range("B2").Text & "\"
        
        CreateObject("WScript.Shell").Run "cmd /c mkdir " & Chr(34) & folder & Chr(34), vbMinimizedNoFocus, True
    
        .SaveCopyAs folder & .ActiveSheet.Range("B3").Text & .ActiveSheet.Range("B2").Text & Mid(.FullName, InStrRev(.FullName, "."))
    End With
    
End Sub
 
Upvote 1

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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