Encontré en la web una macro para enviar el libro activo por mail (Outlook).
Más abajo el código.
La pregunta es acerca de la línea:
TempFileName = "Copia de " & wb1.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")
Entiendo que esta línea le da nombre al archivo temporal que será enviado en el mail.
En ese nombre, se incluye la fecha y hora actuales.
¿Cómo debería ser esta línea para que en el nombre del archivo figure la fecha del DÍA ANTERIOR y sin la hora?
De antemano, agradezco enormemente vuestras respuestas.
Sub MAIL()
'Working in 2000-2010
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim OutApp As Object
Dim OutMail As Object
Set wb1 = ActiveWorkbook
If Val(Application.Version) >= 12 Then
If wb1.FileFormat = 51 And wb1.HasVBProject = True Then
MsgBox "There is VBA code in this xlsx file, there will be no VBA code in the file you send." & vbNewLine & _
"Save the file first as xlsm and then try the macro again.", vbInformation
Exit Sub
End If
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'Make a copy of the file/Open it/Mail it/Delete it
'If you want to change the file name then change only TempFileName
TempFilePath = Environ$("temp") & "\"
TempFileName = "Copia de " & wb1.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")
FileExtStr = "." & Lcase(Right(wb1.Name, Len(wb1.Name) - InStrRev(wb1.Name, ".", , 1)))
wb1.SaveCopyAs TempFilePath & TempFileName & FileExtStr
Set wb2 = Workbooks.Open(TempFilePath & TempFileName & FileExtStr)
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.to = "r.pulido@grupolanin.com.ar"
.CC = "rplabgp@hotmail.com"
.BCC = "rp.pulido@gmail.com"
.Subject = "Producciones GP (a Ventas)"
.Body = "Producciones GP (a Ventas)"
.Attachments.Add wb2.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Display 'or use .Send - '.Display (no envía directo, muestra primero
End With
On Error GoTo 0
wb2.Close savechanges:=False
'Delete the file
Kill TempFilePath & TempFileName & FileExtStr
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
Las fechas son números, así que si restas 1 a la fecha actual tienes la fecha de ayer.
Para mostrar sólo la fecha, sin hora, modifica el formato.
por ejemplo, la parte final de tu línea de código podría ser algo así:
Format(Now - 1, "dd-mmm-yy")
------
Ya sé Excel, pero necesito más ahora en pdf
------
Ya sé Excel, pero necesito más.