Moderatori: Anthony47, Flash30005
Sub Reminders()
Dim shList, ckList, headList, listList, cScad As Long
Dim I As Long, J As Long, K As Long, TCol As Range
Dim mMess As String, Anticipo As Long, Grace As Long
Dim mySplit1, mySplit2
'
Anticipo = 30 '<<< L'anticipo di notifica, i gg
Grace = 15 '<<< Sospensione dell'invio, dopo la mail
shList = Array("Diario corsi", "Programma Sorv Sanitaria", "Programma Sorv Sanitaria")
ckList = Array("tblDiarioCorsi,[SCADENZA]", "Tabella1,[PROX]", "Tabella1,[PROX RX]")
listList = Array("[NOME]", "[COGNOME],[NOME]", "[COGNOME],[NOME]")
headList = Array("Corsi in scadenza:", "Medica periodica in scadenza:", "RX in scadenza:")
For I = 0 To UBound(shList)
mMess = mMess & headList(I) & vbCrLf
Sheets(shList(I)).Select
mySplit1 = Split(ckList(I), ",", , vbTextCompare)
Set TCol = ActiveSheet.Range(mySplit1(0) & mySplit1(1))
For J = 1 To TCol.Rows.Count
If Len(TCol.Cells(J, 1).Value) > 3 Then
If (Date + Anticipo) > TCol.Cells(J, 1) And (Date - Grace) > TCol.Cells(J, 4) Then
TCol.Cells(J, 4).Value = Date
cScad = cScad + 1
mySplit2 = Split(listList(I) & ", ", ",", , vbTextCompare)
mMess = mMess & Format(TCol.Cells(J, 1), "dd-mmm-yyyy") & ", "
For K = 0 To UBound(mySplit2)
If Len(mySplit2(K)) > 1 Then
mMess = mMess & Range(mySplit1(0) & mySplit2(K)).Cells(J, 1) & ", "
End If
Next K
mMess = mMess & vbCrLf
End If
End If
Next J
Next I
Debug.Print mMess
'Messaggio preparato
If cScad > 0 Then
'Ci sono scadenze da comunicare
Dim OutApp As Object, OutMail As Object
'
Set OutApp = CreateObject("Outlook.Application")
EmailAddr = "pippo@Dominio.Com" '<<< INDIRIZZO EMAIL
Subj = "Scadenze prossime del " & Format(Date, "yyyy-mmm-dd") '<<< OGGETTO DELLA MAIL
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = EmailAddr
.CC = ""
.BCC = ""
.Subject = Subj
.Body = mMess
' .send '111
.display '222
End With
Application.Wait (Now + TimeValue("0:00:01"))
' (c)
Set OutMail = Nothing
' (d)
Set OutApp = Nothing
Else
MsgBox ("Non ci sono eventi in scadenza")
End If
End Sub
Corsi in scadenza:
29-giu-2023, c,
17-set-2023, a,
01-lug-2023, b,
04-giu-2021, a,
01-giu-2021, a,
20-nov-2021, a,
17-set-2023, a,
29-giu-2023, a,
Medica periodica in scadenza:
29-lug-2023, a, g,
28-mar-2023, c, e,
17-giu-2023, d, d,
07-nov-2023, e, c,
21-ott-2023, f, b,
RX in scadenza:
Sub Reminders2()
Dim shList, ckList, headList, listList, cScad As Long
Dim I As Long, J As Long, K As Long, TCol As Range
Dim mMess As String, Anticipo As Long, Grace As Long
Dim mySplit1, mySplit2
Dim logPos, dtPos As Range
'
Anticipo = 30 '<<< L'anticipo di notifica, i gg
Grace = 15 '<<< Sospensione dell'invio, dopo la mail
'Descrizioni:
shList = Array("Diario corsi", "Programma Sorv Sanitaria", "Programma Sorv Sanitaria") 'Elenco fogli da processare
ckList = Array("tblDiarioCorsi,[SCADENZA]", "Tabella1,[PROX]", "Tabella1,[PROX RX]") 'Elenco tabelle e colonne data da esaminare
listList = Array("[NOME],[CORSO]", "[COGNOME],[NOME]", "[COGNOME],[NOME]") 'Elenco campi da riportare
headList = Array("Corsi in scadenza:", "Medica periodica in scadenza:", "RX in scadenza:") 'Intestazioni su mail
logPos = Array("[Log]", "[Log1]", "[LogRx]")
'
For I = 0 To UBound(shList)
If I > 0 Then mMess = mMess & "------" & vbCrLf
mMess = mMess & headList(I) & vbCrLf
Sheets(shList(I)).Select
mySplit1 = Split(ckList(I), ",", , vbTextCompare)
Set TCol = ActiveSheet.Range(mySplit1(0) & mySplit1(1))
For J = 1 To TCol.Rows.Count
If Len(TCol.Cells(J, 1).Value) > 3 Then
Set dtPos = Range(mySplit1(0) & logPos(I)).Cells(J, 1)
If (Date + Anticipo) > TCol.Cells(J, 1) And (Date - Grace) > dtPos.Value Then
dtPos.Value = Date
cScad = cScad + 1
mySplit2 = Split(listList(I) & ", ", ",", , vbTextCompare)
mMess = mMess & Format(TCol.Cells(J, 1), "dd-mmm-yyyy") & ", "
For K = 0 To UBound(mySplit2)
If Len(mySplit2(K)) > 1 Then
mMess = mMess & Range(mySplit1(0) & mySplit2(K)).Cells(J, 1) & ", "
End If
Next K
mMess = mMess & vbCrLf
End If
End If
Next J
Next I
mMess = mMess & "------"
Debug.Print mMess
'Messaggio preparato
If cScad > 0 Then
'Ci sono scadenze da comunicare
Dim OutApp As Object, OutMail As Object
'
Set OutApp = CreateObject("Outlook.Application")
EmailAddr = "pippo@Dominio.Com" '<<< INDIRIZZO EMAIL
Subj = "Scadenze prossime del " & Format(Date, "yyyy-mmm-dd") '<<< OGGETTO DELLA MAIL
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = EmailAddr
.CC = ""
.BCC = ""
.Subject = Subj
.Body = mMess
' .send
.display
End With
Application.Wait (Now + TimeValue("0:00:01"))
' (c)
Set OutMail = Nothing
' (d)
Set OutApp = Nothing
Else
MsgBox ("Non ci sono eventi in scadenza")
End If
End Sub
Corsi in scadenza:
29-giu-2023, c, RSPP,
17-set-2023, a, PRIMO SOCCORSO,
01-lug-2023, b, ANTINCENDIO,
04-giu-2021, a, USO CARRELLI INDUSTRIALI,
01-giu-2021, a, RESPONSABILE_GESTIONE RIFIUTI_1_2_4,
20-nov-2021, a, RESPONSABILE_GESTIONE RIFIUTI_3_5,
17-set-2023, a, PRIMO SOCCORSO,
29-giu-2023, a, RSPP,
------
Medica periodica in scadenza:
29-lug-2023, a, g,
28-mar-2023, c, e,
17-giu-2023, d, d,
07-nov-2023, e, c,
21-ott-2023, f, b,
------
RX in scadenza:
------
=LET(Scadenze;tblDiarioCorsi[SCADENZA];Anticipo;A2;myCols;STACK.ORIZ(Scadenze;tblDiarioCorsi[NOME];tblDiarioCorsi[CORSO]);fList;FILTRO(myCols;((OGGI()+Anticipo)>Scadenze)*(Scadenze>0);"");fList)
=LET(Scadenze;Tabella1[PROX];Anticipo;E2;myCols;STACK.ORIZ(Scadenze;Tabella1[COGNOME];Tabella1[NOME]);fList;FILTRO(myCols;((OGGI()+Anticipo)>Scadenze)*(Scadenze>0);"");fList)
=LET(Scadenze;Tabella1[PROX RX];Anticipo;I2;myCols;STACK.ORIZ(Scadenze;Tabella1[COGNOME];Tabella1[NOME]);fList;FILTRO(myCols;((OGGI()+Anticipo)>Scadenze)*(Scadenze>0);"");fList)
Torna a Applicazioni Office Windows
Inserire add.in nella barra di avvio veloce in excel 2003 Autore: Ricky0185 |
Forum: Applicazioni Office Windows Risposte: 4 |
Excel: problema con date se devo unirle a testi Autore: valle1975 |
Forum: Applicazioni Office Windows Risposte: 5 |
confrontare e evidenziare 2 fogli excel Autore: niccia |
Forum: Applicazioni Office Windows Risposte: 7 |
Visitano il forum: Nessuno e 33 ospiti