VB Mail from excel
Hey jeg har fundet en vb kode til at sende emailshar lavet lidt om på det men kan ikke få det til at virke.
jeg kunne også godt tænke mig at den kunne vedhæfte filer
for hver (r, 4 & 10 & 16) = et nummer som er en del af et filnavn
FileName(r, 4) & "a" & ".pdf" og FileName(r, 4) & "b" & ".pdf" for hver at de 3 celler i rækken som har talværdi skal den vedhæfte de filer a og b for hver celle i r, 4 & 10 & 16
filerne finder den i Dir// C:/Text/1/
Hvis det kan lade sig gøre.
Ellers bare hvis der ikke er en mail gå til næste række!!
200 for at løse hele problemet og 100 for hvis mail ikke er der!!
Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Sub SendEMail()
Dim Email As String, Subj As String
Dim Msg As String, URL As String
Dim r As Integer, x As Double
For r = 2 To 25 'data in rows 2-4
' Get the email address
Email = Cells(r, 21)
If Cells(r, 21) = "" Then
Next r
If Cells(r, 21) <> "" Then
' Message subject Format(Cells(r, 2), "hh:mm:ss")
Subj = "Filer" & Cells(r, 4) & ", " & Cells(r, 10) & ", " & Cells(r, 16)
' Compose the message
Msg = "KL" & Cells(r, 2) & vbCrLf
'Tid
Msg = Msg & "" & Format(Cells(r, 1), "hh:mm") & vbCrLf & vbCrLf
Msg = Msg & "" & Cells(r, 4) & " Fra " & Format(Cells(r, 5), "hh:mm") & " " & Cells(r, 6) & " Til " _
& Format(Cells(r, 7), "hh:mm") & " " & Cells(r, 8) & " Info " & Cells(r, 9) & vbCrLf
Msg = Msg & "Og Vif " & Cells(r, 10) & " Fra " & Format(Cells(r, 11), "hh:mm") & " " & Cells(r, 12) & " Til " _
& Format(Cells(r, 13), "hh:mm") & " " & Cells(r, 14) & " Info " & Cells(r, 15) & vbCrLf
Msg = Msg & "Og Vif " & Cells(r, 16) & " Fra " & Format(Cells(r, 17), "hh:mm") & " " & Cells(r, 18) & " Til " _
& Format(Cells(r, 19), "hh:mm") & " " & Cells(r, 20) & vbCrLf
Msg = Msg & "Hilsen" & vbCrLf
Msg = Msg & "Mig"
' Replace spaces with %20 (hex)
Subj = Application.WorksheetFunction.Substitute(Subj, " ", "%20")
Msg = Application.WorksheetFunction.Substitute(Msg, " ", "%20")
' Replace carriage returns with %0D%0A (hex)
Msg = Application.WorksheetFunction.Substitute(Msg, vbCrLf, "%0D%0A")
' Create the URL
URL = "mailto:" & Email & "?subject=" & Subj & "&body=" & Msg
' Execute the URL (start the email client)
ShellExecute 0&, vbNullString, URL, vbNullString, vbNullString, vbNormalFocus
' Wait two seconds before sending keystrokes
Application.Wait (Now + TimeValue("0:00:02"))
Application.SendKeys "%s"
End If
Next r
End Sub
