Create Folder & Save As VBA

tcorcoran15

New Member
Joined
Feb 16, 2017
Messages
22
Hi All,

I have the following macro which works fine, however I would like to expand on it if possible.

I would like the macro to create a file with the date if possible, where the file is then saved.

Potential issue is that I may be running the macro multiple times in a day so I imagine it would need to check whether there is already a folder with today's date? I'm no expert haha.

Any help is greatly appreciated.

Code:
Application.DisplayAlerts = False    ' suppress overwrite warning message        ActiveWorkbook.SaveAs Filename:="X:\Crown Gas & Power\MATRIX\Matrix - Live\Reports\Credit Control Files\" & RemovePunctuation(Range("D2")), _
                          FileFormat:=51, _
                          CreateBackup:=False
                          
        Application.DisplayAlerts = True
        ActiveWorkbook.Close SaveChanges:=False
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
How's this?

Not sure what removepunctuation is so you'll just need to update "filenamehere"

Code:
Sub CheckCreateSave()


Dim myfolder As Object
Dim myfoldername As String


Application.DisplayAlerts = False    ' suppress overwrite warning message
myfoldername = Date


    Set myfolder = CreateObject("Scripting.FileSystemObject")
    If myfolder.folderexists("X:\Crown Gas & Power\MATRIX\Matrix - Live\Reports\Credit Control Files\" & myfoldername) Then
    GoTo folderexists
    Else
        myfolder.CreateFolder ("X:\Crown Gas & Power\MATRIX\Matrix - Live\Reports\Credit Control Files\" & myfoldername)
    End If


folderexists:
ActiveWorkbook.SaveAs Filename:="X:\Crown Gas & Power\MATRIX\Matrix - Live\Reports\Credit Control Files\" & myfoldername & "\" & filenamehere
Application.DisplayAlerts = True
ActiveWorkbook.Close SaveChanges:=False


End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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