27. april 2007 - 11:38
#6
Det havde jeg også lavet den om til...
Men der virker vist ikke efter hensigt,
Men det kan være man lige skal se koden som den er...
På arket henter den mailadresserne og hvilken filer den skal sende med på mailen.
Min kode som den er nu ser sådan her ud...
'---------------------------------------------------
Option Explicit
Sub SendEMail()
Dim Email As String, Subj As String
Dim MSG As String, URL As String
Dim r As Integer
If Format(Now(), "D") > Format(Now() + 1, "D") Then
Cells(2, 30) = "1"
Else
Cells(2, 30) = ""
End If
For r = 4 To 35
Email = Cells(r, 30)
If Cells(r, 3) <> "" Then
If Cells(r, 2) <> "" And Cells(r, 29) <> "" And Cells(r, 30) <> "" Then
bygMail r
ElseIf Cells(r, 2) = "" And Cells(r, 3) <> "" Then
MsgBox Cells(r, 3) & "" & vbCrLf & ""
Cells(r, 2).Interior.ColorIndex = 3
ElseIf Cells(r, 29) = "" And Cells(r, 3) <> "" Then
MsgBox Cells(r, 3) & "" & vbCrLf & ""
Cells(r, 29).Interior.ColorIndex = 3
End If
End If
Next r
End Sub
'---------------------------------------------------
Private Sub bygMail(r)
Dim mailThis As Outlook.MailItem
Dim MSG As String, Email As String, Subj As String, Disk As String, Filnavn As String
Disk = "\\server\Data\" & Format(Now(), "dddd") & "\"
Filnavn = ".pdf"
Vv1 = "Vi"
Kl1 = "KL"
Kl2 = "wL"
Kl3 = "wsL"
Kv1 = "V"
Kv2 = "wV"
Kv3 = "wsV"
Ms1 = "BT. "
Ms2 = "AT. "
Ms3 = "D. "
Ms4 = "S. "
MsH1 = "FT. "
MsH2 = "AT. "
MsH3 = "TT. "
MsH4 = "FTV. "
Fr = " FR ": Ti = " Ti "
C1 = "Bn": C2 = "T": C3 = "D": C4 = "R"
'---------------------------------------------------
Set mailThis = CreateItem(olMailItem)
Email = Cells(r, 30)
Subj = "" & "" & Cells(r, 4) & ": " & Cells(r, 5) & ", " & Cells(r, 11) & ", " & Cells(r, 17) & ", " & Cells(r, 23) & ". Til /" & Format(Now() + 1, "dddd dd mmmm yyyy") & "\ Sendt " & Format(Now(), "dddd mmmm yy hh:mm")
MSG = "Hey " & Cells(r, 3) & vbCrLf
If (Cells(r, 2)) <> "" Then
MSG = MSG & "" & Format(Cells(r, 2), "hh:mm") & "" & Format(Cells(r, 29), "hh:mm") & vbCrLf & vbCrLf
End If
If (Cells(1, 4)) <> "" Then
MSG = MSG & Cells(1, 4) & vbCrLf & vbCrLf
End If
If (Cells(2, 4)) <> "" Then
MSG = MSG & Cells(2, 4) & vbCrLf & vbCrLf
End If
If (Cells(r, 1)) <> "" Then
MSG = MSG & Cells(r, 1) & vbCrLf & vbCrLf
End If
'---------------------------------------------------
Select Case (Cells(r, 5))
Case C1
MSG = MSG & Ms1 & Fr & Format(Cells(r, 6), "hh:mm") & " " & Cells(r, 7) & Ti & Format(Cells(r, 8), "hh:mm") & " " & Cells(r, 9) & vbCrLf
Case C2
MSG = MSG & Ms2 & Fr & Format(Cells(r, 6), "hh:mm") & " " & Cells(r, 7) & Ti & Format(Cells(r, 8), "hh:mm") & " " & Cells(r, 9) & vbCrLf
Case C3
MSG = MSG & Ms3 & Fr & Format(Cells(r, 6), "hh:mm") & " " & Cells(r, 7) & Ti & Format(Cells(r, 8), "hh:mm") & " " & Cells(r, 9) & vbCrLf
Case C4
MSG = MSG & Ms4 & Fr & Format(Cells(r, 6), "hh:mm") & " " & Cells(r, 7) & Ti & Format(Cells(r, 8), "hh:mm") & " " & Cells(r, 9) & vbCrLf
Case 11 To 35
MSG = MSG & MsH1 & Cells(r, 5) & Fr & Format(Cells(r, 6), "hh:mm") & " " & Cells(r, 7) & Ti & Format(Cells(r, 8), "hh:mm") & " " & Cells(r, 9) & vbCrLf
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 5) & Kl1 & Filnavn) <> "" Then
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 5) & Kv1 & Filnavn) <> "" Then
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 5) & Kl1 & Filnavn
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 5) & Kv1 & Filnavn
Else
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 5) & Kl1 & Filnavn
End If
Else
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 5) & Kl2 & Filnavn) <> "" Then
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 5) & Kv2 & Filnavn) <> "" Then
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 5) & Kl2 & Filnavn
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 5) & Kv2 & Filnavn
Else
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 5) & Kl2 & Filnavn
End If
Else
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 5) & Kl3 & Filnavn) <> "" Then
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 5) & Kv3 & Filnavn) <> "" Then
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 5) & Kl3 & Filnavn
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 5) & Kv3 & Filnavn
Else
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 5) & Kl3 & Filnavn
End If
End If
End If
End If
Case Else
End Select
'---------------------------------------------------
Select Case (Cells(r, 11))
Case C1
MSG = MSG & Ms1 & Fr & Format(Cells(r, 12), "hh:mm") & " " & Cells(r, 13) & Ti & Format(Cells(r, 14), "hh:mm") & " " & Cells(r, 15) & vbCrLf
Case C2
MSG = MSG & Ms2 & Fr & Format(Cells(r, 12), "hh:mm") & " " & Cells(r, 13) & Ti & Format(Cells(r, 14), "hh:mm") & " " & Cells(r, 15) & vbCrLf
Case C3
MSG = MSG & Ms3 & Fr & Format(Cells(r, 12), "hh:mm") & " " & Cells(r, 13) & Ti & Format(Cells(r, 14), "hh:mm") & " " & Cells(r, 15) & vbCrLf
Case C4
MSG = MSG & Ms4 & Fr & Format(Cells(r, 12), "hh:mm") & " " & Cells(r, 13) & Ti & Format(Cells(r, 14), "hh:mm") & " " & Cells(r, 15) & vbCrLf
Case 11 To 35
MSG = MSG & MsH2 & Cells(r, 11) & Fr & Format(Cells(r, 12), "hh:mm") & " " & Cells(r, 13) & Ti & Format(Cells(r, 14), "hh:mm") & " " & Cells(r, 15) & vbCrLf
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 11) & Kl1 & Filnavn) <> "" Then
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 11) & Kv1 & Filnavn) <> "" Then
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 11) & Kl1 & Filnavn
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 11) & Kv1 & Filnavn
Else
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 11) & Kl1 & Filnavn
End If
Else
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 11) & Kl2 & Filnavn) <> "" Then
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 11) & Kv2 & Filnavn) <> "" Then
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 11) & Kl2 & Filnavn
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 11) & Kv2 & Filnavn
Else
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 11) & Kl2 & Filnavn
End If
Else
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 11) & Kl3 & Filnavn) <> "" Then
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 11) & Kv3 & Filnavn) <> "" Then
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 11) & Kl3 & Filnavn
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 11) & Kv3 & Filnavn
Else
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 11) & Kl3 & Filnavn
End If
End If
End If
End If
Case Else
End Select
'---------------------------------------------------
Select Case (Cells(r, 17))
Case C1
MSG = MSG & Ms1 & Fr & Format(Cells(r, 18), "hh:mm") & " " & Cells(r, 19) & Ti & Format(Cells(r, 20), "hh:mm") & " " & Cells(r, 21) & vbCrLf
Case C2
MSG = MSG & Ms2 & Fr & Format(Cells(r, 18), "hh:mm") & " " & Cells(r, 19) & Ti & Format(Cells(r, 20), "hh:mm") & " " & Cells(r, 21) & vbCrLf
Case C3
MSG = MSG & Ms3 & Fr & Format(Cells(r, 18), "hh:mm") & " " & Cells(r, 19) & Ti & Format(Cells(r, 20), "hh:mm") & " " & Cells(r, 21) & vbCrLf
Case C4
MSG = MSG & Ms4 & Fr & Format(Cells(r, 18), "hh:mm") & " " & Cells(r, 19) & Ti & Format(Cells(r, 20), "hh:mm") & " " & Cells(r, 21) & vbCrLf
Case 11 To 35
MSG = MSG & MsH3 & Cells(r, 17) & Fr & Format(Cells(r, 18), "hh:mm") & " " & Cells(r, 19) & Ti & Format(Cells(r, 20), "hh:mm") & " " & Cells(r, 21) & vbCrLf
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 17) & Kl1 & Filnavn) <> "" Then
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 17) & Kv1 & Filnavn) <> "" Then
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 17) & Kl1 & Filnavn
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 17) & Kv1 & Filnavn
Else
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 17) & Kl1 & Filnavn
End If
Else
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 17) & Kl2 & Filnavn) <> "" Then
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 17) & Kv2 & Filnavn) <> "" Then
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 17) & Kl2 & Filnavn
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 17) & Kv2 & Filnavn
Else
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 17) & Kl2 & Filnavn
End If
Else
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 17) & Kl3 & Filnavn) <> "" Then
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 17) & Kv3 & Filnavn) <> "" Then
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 17) & Kl3 & Filnavn
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 17) & Kv3 & Filnavn
Else
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 17) & Kl3 & Filnavn
End If
End If
End If
End If
Case Else
End Select
'---------------------------------------------------
Select Case (Cells(r, 23))
Case C1
MSG = MSG & Ms1 & Fr & Format(Cells(r, 24), "hh:mm") & " " & Cells(r, 25) & Ti & Format(Cells(r, 26), "hh:mm") & " " & Cells(r, 27) & vbCrLf
Case C2
MSG = MSG & Ms2 & Fr & Format(Cells(r, 24), "hh:mm") & " " & Cells(r, 25) & Ti & Format(Cells(r, 26), "hh:mm") & " " & Cells(r, 27) & vbCrLf
Case C3
MSG = MSG & Ms2 & Fr & Format(Cells(r, 24), "hh:mm") & " " & Cells(r, 25) & Ti & Format(Cells(r, 26), "hh:mm") & " " & Cells(r, 27) & vbCrLf
Case C4
MSG = MSG & Ms4 & Fr & Format(Cells(r, 24), "hh:mm") & " " & Cells(r, 25) & Ti & Format(Cells(r, 26), "hh:mm") & " " & Cells(r, 27) & vbCrLf
Case 11 To 35
MSG = MSG & MsH4 & Cells(r, 23) & Fr & Format(Cells(r, 24), "hh:mm") & " " & Cells(r, 25) & Ti & Format(Cells(r, 26), "hh:mm") & " " & Cells(r, 27) & vbCrLf
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 23) & Kl1 & Filnavn) <> "" Then
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 23) & Kv1 & Filnavn) <> "" Then
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 23) & Kl1 & Filnavn
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 23) & Kv1 & Filnavn
Else
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 23) & Kl1 & Filnavn
End If
Else
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 23) & Kl2 & Filnavn) <> "" Then
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 23) & Kv2 & Filnavn) <> "" Then
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 23) & Kl2 & Filnavn
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 23) & Kv2 & Filnavn
Else
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 23) & Kl2 & Filnavn
End If
Else
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 23) & Kl3 & Filnavn) <> "" Then
If Dir(Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 23) & Kv3 & Filnavn) <> "" Then
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 23) & Kl3 & Filnavn
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 23) & Kv3 & Filnavn
Else
mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now() + Cells(2, 30), "mm") & Format(Now() + 1, "dd") & Vv1 & Cells(r, 23) & Kl3 & Filnavn
End If
End If
End If
End If
Case Else
End Select
'---------------------------------------------------
MSG = MSG & "" & vbCrLf
MSG = MSG & "" & vbCrLf & vbCrLf
MSG = MSG & Cells(5, 33) & vbCrLf
MSG = MSG & Cells(6, 33) & vbCrLf
MSG = MSG & Cells(7, 33) & vbCrLf
MSG = MSG & Cells(8, 33) & vbCrLf
MSG = MSG & Cells(9, 33) & vbCrLf
MSG = MSG & Cells(10, 33) & vbCrLf
MSG = MSG & Cells(12, 33) & vbCrLf
MSG = MSG & Cells(13, 33) & vbCrLf
MSG = MSG & Cells(14, 33) & vbCrLf
MSG = MSG & Cells(15, 33) & vbCrLf
'---------------------------------------------------
If Application.Wait(Now + TimeValue("0:00:03")) Then
'MsgBox "Mail til " & Cells(r, 3) & " Klar"
Cells(r, 30).Interior.ColorIndex = 4
End If
'---------------------------------------------------
mailThis.Recipients.Add Email
mailThis.Subject = Subj
mailThis.Body = MSG
mailThis.Display 'mailThis.Save 'mailThis.Send
End Sub