2
Good morning guys, I need some help.. I have this macro she’s working perfectly but I need to add 1 things to it.
When she run and generate the new file with the tabs I selected, I need you to open the outlook, that new file gets attached to it.
someone can help me?
follows the Cod.
' MACRO PARA CRIAR PASTA DE ANO/MES/DIA
Public Const sCaminho = "pasta local para salvar"
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 salvareenviaremail()
Dim data As Date
data = Now()
Call fnccriardiretorio(data)
Dim ws3 As Worksheet
Dim UltimaLinhaE As Long
fname1 = (sCaminho & "\" & Format(data, "yyyy") & _
"\" & Format(data, "mmmm")) & "\" & Format(data, "dd") & _
"\" & "nome do arquivo"
Worksheets(Array("Planilha1", "Planilha2", "Planilha3")).Copy
Set ws3 = ActiveWorkbook.Worksheets("Planilha3")
With ws3
'Limpa os Autofiltros da Planilha para evitar erros
If .FilterMode Then
.ShowAllData
End If
'Última Linhada colunaE
UltimaLinhaE = .Cells(.Rows.Count, "E").End(xlUp).Row
'Autofiltro
.Range("E1:E" & UltimaLinhaE).AutoFilter Field:=5, Criteria1:="Cell 01"
End With
Set ws4 = ActiveWorkbook.Worksheets("Planilha2")
With ws4
'Limpa os Autofiltros da Planilha para evitar erros
If .FilterMode Then
.ShowAllData
End If
'Última Linhada colunaE
UltimaLinhaE = .Cells(.Rows.Count, "E").End(xlUp).Row
'Autofiltro
.Range("E1:E" & UltimaLinhaE).AutoFilter Field:=5, Criteria1:="Cell 02"
End With
With ActiveWorkbook
ActiveWorkbook.SaveAs Filename:=fname1, FileFormat:=xlOpenXMLWorkbookMacroEnabled
End With
End Sub
Show @max thanks now leaves me a doubt, you know the new file that was generated? how do I attach, it does not have a default folder, because the macro creates a daily folder for it, have any idea?
– John Hebert
Obs: It does not have a default folder
– John Hebert
You have a few options; you can set a specific location to save these sheets; or you can adapt the attachment row if you follow a logical order (for example, every day increases the final value by 1, or the date is added); or when you run the macro you can call a window that asks which file will be attached
– Evilmaax
how it would look... when you run the macro you can call a window that asks which file will be attached?
– John Hebert
I did the code editing. Check if it works right as I do not have Outlook configured here on the machine to do the tests
– Evilmaax
perfect, thank you so much for your help
– John Hebert
@Johnhebert If you helped, don’t forget to vote yes and validate the answer as "Accept" by clicking on the Check sign. This will help other people who arrive here with the same doubt. And if you need, dispose.
– Evilmaax
done, thank you!
– John Hebert