
Option Explicit
Sub Mail()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''' ATTENZIONE RICHIEDE L'ATTIVAZIONE DELLA LIBRERIA MICROSOFT OUTLOOK 14.0 OBJECT LIBRARY '''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''' Per l'attivazione andare su "Strumenti", "Riferimenti", cercare e spuntare il nome '''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim sAddr As String, sBody As String, sObj As String, sFrom As String, sAttc As String
Dim oOUT As Outlook.Application
Dim oML As MailItem
Dim x As Long, i As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Email")
x = ws.Range("B" & ws.Rows.Count).End(xlUp).Row
Set oOUT = CreateObject("Outlook.Application")
For i = 6 To x
sAddr = Cells(i, 3) 'Destinatario
sObj = Cells(i, 4) 'Oggetto
sBody = Cells(i, 5) 'Testo
sAddr = Cells(i, 6) 'Allegato
sFrom = Cells(i, 2) 'Mittente
Set oML = oOUT.CreateItem(olMailItem)
With oML
.Attachments.Add sAttc
.To = sAddr
.Subject = sObj
.Body = sBody
.SentOnBehalfOfName = sFrom
.Display
'.Send
End With
Next i
Set oOUT = Nothing
Set oML = Nothing
Set ws = Nothing
End Sub
|
Private Sub CommandButton21_Click() Dim strCommand As String strCommand = "C:Program Files (x86)Mozilla Thunderbird hunderbird" strCommand = strCommand & " -compose " & Chr$(34) & "mailto:" & strTo & "?" strCommand = strCommand & "subject=Comunicazione & Chr$(34) & strSubject & Chr$(34) & " & "" strCommand = strCommand & "body= & Chr$(34) & strBody & Chr$(34)" Call Shell(strCommand, vbNormalFocus) End Sub |
Option Explicit
Function GetDefaultEmailProgramName() As String
'Written: November 30, 2008
'Author: Leith Ross
'Summary: Function returns the name of the default email program.
' This works with Excel 2000 and up.
Dim DefaultEmail As String
Dim I As Long
Dim ProgPath As Variant
Dim WSH As Object
Set WSH = CreateObject("WScript.Shell")
DefaultEmail = WSH.RegRead("HKCRmailtoshellopencommand")
I = InStr(2, DefaultEmail, Chr$(34))
DefaultEmail = Mid(DefaultEmail, 2, I - 2)
'This separates the email program name from the full path
ProgPath = Split(DefaultEmail, "")
GetDefaultEmailProgramName = ProgPath(UBound(ProgPath))
Set WSH = Nothing
End Function
Sub Mail()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''' ATTENZIONE RICHIEDE L'ATTIVAZIONE DELLA LIBRERIA MICROSOFT OUTLOOK 14.0 OBJECT LIBRARY '''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''' Per l'attivazione andare su "Strumenti", "Riferimenti", cercare e spuntare il nome '''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim sAddr As String, sBody As String, sObj As String, sFrom As String, sAttc As String
Dim oOUT As Outlook.Application
Dim oML As MailItem
Dim x As Long, I As Long
Dim ws As Worksheet
Dim s As String
Set ws = ThisWorkbook.Worksheets("Email")
x = ws.Range("B" & ws.Rows.Count).End(xlUp).Row
s = GetDefaultEmailProgramName() 's = "thunderbird.exe"
Set oOUT = CreateObject(s) 'crashes here
'Set oOUT = CreateObject("Outlook.Application")
For I = 6 To x
sAddr = Cells(I, 3) 'Destinatario
sObj = Cells(I, 4) 'Oggetto
sBody = Cells(I, 5) 'Testo
sAddr = Cells(I, 6) 'Allegato
sFrom = Cells(I, 2) 'Mittente
Set oMail = oOUT.CreateItem(olMailItem)
With oMail
.Attachments.Add sAttc
.To = sAddr
.Subject = sObj
.Body = sBody
.SentOnBehalfOfName = sFrom
.Display
'.Send
End With
Next I
Set oOUT = Nothing
Set oML = Nothing
Set ws = Nothing
End Sub |
Dim oOUT As Object Dim oMailL As Object e NON Dim oOUT As Outlook.Application Dim oML As MailItem |
