Saving file automatically VBA

2

I made this macro to create folders and subfolders automatically, but I need to save the file I'm editing inside the created pasture ... can anyone help me?

Follow the script

' MACRO PARA CRIAR PASTA DE ANO/MES/DIA

Public Const sCaminho = ""
Dim Pasta As New FileSystemObject

Public Function fnccriardiretorio(data As Date)
If Pasta.FolderExists(sCaminho & "\" & Format(data, "yyyy")) Then
    fncmes (data)
Else
    Pasta.CreateFolder (sCaminho & "\" & Format(data, "yyyy"))
    fncmes (data)
End If


End Function

Public Function fncmes(data As Date)
If Pasta.FolderExists(sCaminho & "\" & Format(data, "yyyy") & _
"\" & Format(data, "mmmm")) Then
    Call fncdia(data)
Else
    Pasta.CreateFolder (sCaminho & "\" & Format(data, "yyyy") & _
"\" & Format(data, "mmmm"))
    Call fncdia(data)
End If
End Function

Public Function fncdia(data As Date)
If Pasta.FolderExists(sCaminho & "\" & Format(data, "yyyy") & _
"\" & Format(data, "mmmm") & "\" & Format(data, "dd")) Then

Else
    Pasta.CreateFolder (sCaminho & "\" & Format(data, "yyyy") & _
"\" & Format(data, "mmmm")) & "\" & Format(data, "dd")
End If


End Function
Sub chamafuncao()
Dim data As Date
data = InputBox("Entre com a Data _EX DD/MM/AAAA")
Call fnccriardiretorio(data)
End Sub
    
asked by anonymous 16.05.2018 / 19:49

1 answer

2

To save the file itself in xlsm format in the folder you created, you can use the SaveAs method of the Workbook.

fname = (sCaminho & "\" & Format(data, "yyyy") & _
"\" & Format(data, "mmmm")) & "\" & Format(data, "dd") & _
"\" & "nomedoarquivo"

Workbook.SaveAs FileName:=fname, FileFormat:=xlOpenXMLWorkbookMacroEnabled
    
16.05.2018 / 21:03