Spero di non sbagliare aprendo una nuova discussione per argomenti trattati molto tempo nel forum, nel caso non me ne vogliano i moderatori.
Seguendo i vari consigli di questo forum sono riuscito ad adattare il codice vba alle mie esigenze. Credo di fare cosa gradita postandolo di seguito:
- Codice: Seleziona tutto
Sub InvioMail()
Dim OLook As Object 'Outlook.Application
Dim MItem As Object 'Outlook.MailItem
Dim Inter As String, CScad As Integer
Dim R As Integer, C As Integer
Dim MAddr As String, MSubj As String
Dim Sog As String
Dim TurN As String, ZO As String, nA As String, ST As String
If (Selection.Rows.Count + Selection.Columns.Count) > 2 Then Exit Sub
With Sheets("Dati")
If .Cells(27, 5).Text = "" Then Exit Sub
MAddr = .Cells(27, 5).Text
Sog = .Cells(29, 5).Text
End With
With ActiveSheet
R = ActiveCell.Row
MSubj = "Orario di " & Sog & " " & .Cells(R, 6).Text '<<<< Subject della mail
Set OLook = CreateObject("Outlook.Application")
Set MItem = OLook.createitem(0)
MItem.to = MAddr
MItem.Subject = MSubj
'------------
If .Cells(R, 12).Text <> "" And .Cells(R, 9).Text <> "" Then TurN = "scrivi questo"
If .Cells(R, 14).Text <> "" And .Cells(R, 9).Text <> "" Then ZO = "scrivi 2"
If .Cells(R, 16).Text <> "" And .Cells(R, 9).Text <> "" Then nA = "scirivi 3"
If .Cells(R, 9).Text = "" Then MItem.Body = "Il " & .Cells(R, 6).Text & " scrivi 4" _
& vbCrLf & .Cells(R, 8).Text Else
If .Cells(R, 9).Text <> "" And .Cells(R, 11).Text = "" Then SecTurn = "" Else _
ST = "Inizio: " & .Cells(R, 10).Text & " Fine: " & .Cells(R, 11).Text & vbCrLf & vbCrLf
MItem.Body = "testo completo della mail " & .Cells(R, 6).Text & ":" & vbCrLf_
& "Inizio: " & .Cells(R, 8).Text & " Fine: " & .Cells(R, 9).Text _
& vbCrLf & vbCrLf & ST & TurN & vbCrLf & ZO & vbCrLf & nA
MItem.send
Application.Wait (Now + TimeValue("0:00:05"))
Set OLook = Nothing
Set MItem = Nothing
End With
End Sub
In pratica cliccando su un tastino nel foglio invia una mail all'indirizzo di posta elettronica specificato in una cella del foglio "DATI", recuperando i dati da inserire nella mail, dalla riga cui viene selezionata una cella.
La macro funziona egregiamente su alcuni pc (win 10 e office 2013) ma non su altri (win 7 e office 2010). Su questi ultimi si deve necessariamente avviare prima outlook per far si che tutto funzioni correttamente.
Sapete aiutarmi?