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
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