Create Folder with date ( as per Cell Reff ) and Save Current File in it

sg2209

Board Regular
Joined
Oct 27, 2017
Messages
117
Office Version
  1. 2016
Dear Friends,

i am new to VBA and keep practising by recording a Macro, check forums and solutuions and videos.

I am able to write a macro with the help of forums and its working though but as per my expectations , i have written a code where Folder is being created with the date and however file is not getting saved in it, File is also saving in the main folder where new folder i have created .
i am trying wrting a code becuase daily a date gets changed and i need folder creates with vba and file gets save in it

Sub Prep_InsCr_Balance()

Dim MyFile As String
MyFile = ActiveWorkbook.Name
Dim FileName As String
Dim FilePath As String
Dim sFolderName As String, sFolder As String
Dim sFolderPath As String

'Main Folder
sFolder = Range("Checker!A6").Value LOcation in Cell A6 \56.2.122.12\20007001_n01_bsnl\Csh ppl\

sFolderName = Format(Now(), "mm-dd-yy")

'Folder Path
sFolderPath = Range("Checker!A2").Value & sFolderName Location in Cell A2 \\56.2.122.12\20007001_n01_bsnl\Csh ppl\Sachin\ ( Folder should create in Sachin and then file save in it )


'Create FSO Object
Set oFSO = CreateObject("Scripting.FileSystemObject")


'Check Specified Folder exists or not
If oFSO.FolderExists(sFolderPath) Then

'If folder is available with today's date
MsgBox "Folder already exists with today's date!", vbInformation, "VBAF1"
Exit Sub
Else
'Create Folder
MkDir sFolderPath

'Display message on the screen
MsgBox "Folder has created with today's date: " & vbCrLf & vbCrLf & sFolderPath, vbInformation, "VBAF1"
End If

FileName = Range("Checker!A1").Value ' Name of the File ( Name of the File )


ActiveWorkbook.SaveAs (sFolderPath & FileName)
'ActiveWorkbook.Close


Please help if anything i am doiung is incorrect


End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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