
Sub Inviamail(mail As String, file As String, ccmail As String, j As Integer)
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
Dim bodymail As String
Dim c As Integer
Dim i As Integer
Dim mail As String
Dim ccmail As String
Dim file As String
Dim percorso As String
Range("D:D").ClearContents
percorso = Cells(1, 6)
If Right$(percorso, 1) <> "" Then percorso = percorso & ""
'Set rng = Sheets("YourSheet").Range("D4:D12").SpecialCells(xlCellTypeVisible)
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
firma = "C:UsersITFontanAn1AppDataRoamingMicrosoftSignaturesAndrea.Htm"
If Dir(firma) <> "" Then
Sign = GetBoiler(firma)
Else
Sign = ""
End If
j = 2
On Error Resume Next
With OutMail
While Trim(Cells(j, 1)) <> ""
conta = Application.WorksheetFunction.CountIf(Range("A:A"), Cells(j, 1))
Set rng = Sheets("Foglio1").Range("Cells(j, 2), Cells (j + conta - 1, 3)").SpecialCells(xlCellTypeVisible)
.From = "carletto@dominio.com"
.To = Cells(j, 1)
.CC = Trim(Cells(j, 3))
.Subject = Cells(12, 6)
file = percorso + Cells(j, 2)
.BodyFormat = olFormatHTML
bodymail = ""
bodymail = bodymail + Cells(13, 6) + " |
Sub Inviamail(mail As String, file As String, ccmail As String, j As Integer) |
Sub Inviamail(mail As String, file As String, ccmail As String, j As Integer)
Sub Telaio2_Click()
Inviamail
End Sub
Inviamail(mail as String, file as String, ccmail as String, j as Integer) ---------------------------------------- Inviamail(mail, file, ccmail, j) |
Sub Inviamail(mail As String, file As String, ccmail As String, j As Integer)
Inviamail
Call Inviamail
Inviamail param1, param2, param3, param4
Call Inviamail(param1, param2, param3, param4)
Sub Telaio2_Click()
Inviamail "primo parametro stringa (mail)", "secondo parametro stringa (file)", "terzo parametro stringa (ccmail)", 99
Sub Inviamail(mail As String, file As String, ccmail As String, j As Integer, conta As Integer)
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
Dim bodymail As String
Dim c As Integer
Dim i As Integer
Dim percorso As String
Range("D:D").ClearContents
percorso = Cells(1, 6)
If Right$(percorso, 1) <> "" Then percorso = percorso & ""
'Set rng = Sheets("YourSheet").Range("D4:D12").SpecialCells(xlCellTypeVisible)
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
firma = "firma"
If Dir(firma) <> "" Then
Sign = GetBoiler(firma)
Else
Sign = ""
End If
j = 2
On Error Resume Next
With OutMail
While Trim(Cells(j, 1)) <> ""
conta = Application.WorksheetFunction.CountIf(Range("A:A"), Cells(j, 1))
Set rng = Range("Cells(j, 2), Cells(j + conta - 1, 3)").Select
.From = "mionome@dominio.com"
.To = Cells(j, 1)
.CC = Trim(Cells(j, 3))
.Subject = Cells(12, 6)
file = percorso + Cells(j, 2)
.BodyFormat = olFormatHTML
bodymail = ""
bodymail = bodymail + Cells(13, 6) + " |
Sub Telaio2_Click()
Inviamail mail, file, ccmail, j, conta
End Sub
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"
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
Function GetBoiler(ByVal sFile As String) As String
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.readall
ts.Close
End Function
Sub Inviamail(mail As String, file As String, ccmail As String, j As Integer, conta As Integer, rng As Range)
Dim OutApp As Object
Dim OutMail As Object
Dim bodymail As String
'Set rng = Sheets("YourSheet").Range("D4:D12").SpecialCells(xlCellTypeVisible)
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
firma = "C:UsersCarlettoAppDataRoamingMicrosoftSignaturesCarletto.Htm"
If Dir(firma) <> "" Then
Sign = GetBoiler(firma)
Else
Sign = ""
End If
On Error Resume Next
With OutMail
.From = "carletto@dominio.com"
.To = mail
.cc = Trim(ccmail)
.Subject = Cells(12, 6)
.BodyFormat = olFormatHTML
bodymail = ""
bodymail = bodymail + Cells(13, 6) + " |
Set rng = Range("Cells(j, 4), Cells(j + conta - 1, 5)")
Set rng = Range(Cells(j, 4), Cells(j + conta - 1, 5))
percorso = Cells(1, 6)
percorso = Range("F1")Inviamail mail, file, ccmail, j, conta, Union(Range("D1:E1"), rng)
Range("D:D").ClearContents
