Ciao DR_307.
Nel mio ufficio ho la necessita' di inviare ogni lunedi mattina alle 9.00 una email in cui venga inserita una tabella estratta da un foglio excel secondo le date inserite in 2 colonne specifiche e la mail inviata a 3/4 indirizzi email sempre gli stessi.
praticamente secondo le date inserite nelle due colonne indicate vorrei che venisse inviata la tabella come nell'immagine sotto sempre alle stesse 4 persone ogni lunedi.
tenendo conto che le righe da prendere in considerazione sono solo quelle che comprendono le date passate rispetto al lunedi di invio e quelle comprese tra il lunedi di invio e il lunedi successivo. posso anche inviare il file se serve per capire meglio.

.
Sarebbe utile vedere un esempio del tuo file e il rapporto desiderato.
Comunque, in attesa, prova qualcosa del genere:
- Alt+F11 per aprire l'editor di VBA
- Alt+IM per inserire un nuovo modulo di codice
- Nel nuovo modulo vuoto, incolla il seguente codice:
'========>>
Option Explicit
'-------->>
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim oTabella As ListObject
Dim Rng As Range
Const sFoglio As String = **"Foglio1" '<<=== Modifica**
Const sTabella As String = **"Table1" '<<=== Modifica**
Const sDestinatarie As String = **"PippoAToutlook.com;******@gmail.com" '<<=== Modifica**
Const sOggetto As String = **"REPORT" '<<=== Modifica**
Set WB = ThisWorkbook
Set SH = WB.Sheets(sFoglio)
Set oTabella = SH.ListObjects(sTabella)
With oTabella
.DataBodyRange.Columns(10).Resize(, 2).NumberFormat = "General"
With .Range
.AutoFilter Field:=12, Criteria1:= \_
">=" & CLng(Date), Operator:=xlAnd, Criteria2:="<=" & CLng(Date) + 7
.AutoFilter Field:=13, Criteria1:= \_
">=" & CLng(Date), Operator:=xlAnd, Criteria2:="<=" & CLng(Date) + 7
Set Rng = .SpecialCells(xlCellTypeVisible)
End With
If Not Rng Is Nothing Then
Call Invia\_Mail\_HTML(Rng, sDestinatarie, sOggetto)
Else
Call MsgBox(Prompt:="Nessun dato trovato per la settimana corrispondente!", \_
Buttons:=vbCritical, \_
Title:="REPORT")
End If
.AutoFilter.ShowAllData
End With
End Sub
'-------->>
Public Sub Invia_Mail_HTML(oRng As Range, sRecipient As String, sSubject As String)
Dim oOutlook As Object
Dim oMail As Object
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set oOutlook = CreateObject("Outlook.Application")
Set oMail = oOutlook.CreateItem(0)
On Error Resume Next
With oMail
.To = sRecipient
.CC = ""
.BCC = ""
.Subject = sSubject
.HTMLBody = RangetoHTML(oRng)
.Display '\\ .Send
End With
On Error GoTo 0
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set oMail = Nothing
Set oOutlook = Nothing
End Sub
'--------->>
Public Function RangetoHTML(Rng As Range)
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook
TempFile = Environ$("temp") & "" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
'Copy the range and create a new workbook to past the data in
Rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With
'Publish the sheet to a htm file
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
FileName:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
'Read all data from the htm file into RangetoHTML
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.readall
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")
'Close TempWB
TempWB.Close savechanges:=False
'Delete the htm file we used in this function
Kill TempFile
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function
'<<========
- Alt+Q per chiudere l'editor di VBA e tornare a Excel.
- Salva il file con l'estensione xlsm
- Alt+F8 per aprire la finestra di gestione delle macro
- Seleziona Tester
- Esegui
===
Regards,
Norman
