Avatar billede sjokoman Juniormester
03. september 2007 - 21:21 Der er 5 kommentarer og
1 løsning

Mine pdf filer er ændret så nu kan jeg ikke sende email mere

Jeg har en linje (made by Splokit):
        mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now(), "mm") & Format(Now() + 1, "dd") & Cells(2, 9) & Cells(r, 16) & "KV" & Filnavn

som tager nogle filer og vedhæfter dem mine mails (flere ad gangen), der bliver sendt automatisk, når jeg trykker på send.
Normalt ser mine pdf filer således ud:
20070904DNT-35KL.pdf
nu ser de således ud:
20070904DNT-35aKL.pdf
20070904DNT-35bKL.pdf
20070904DNT-35cKL.pdf
20070904DNT-35dKL.pdf
altså enten et a eller b eller  c eller d midt i.
Det vil vba ikke tage. Jeg kan godt sætte et bogstav foran i linjen  "xKL" "xKV" og få det til at virke, hvis filen også har et x men har den et andet, stopper VBA.
Hvordan kommer jeg videre?
mvh Johnny
Avatar billede sjokoman Juniormester
03. september 2007 - 21:29 #1
manglede lige en linje:
        mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now(), "mm") & Format(Now() + 1, "dd") & Cells(2, 9) & Cells(r, 16) & "KL" & Filnavn
Avatar billede jlemming Nybegynder
04. september 2007 - 15:32 #2
Hvad har du til at stå i cells(r,16) før og efter, og hvilke format har cellen ?
Avatar billede sjokoman Juniormester
04. september 2007 - 19:47 #3
Det er næsten lettere, du ser hele modulet, jeg er ikke sikker på kolonne og række, måske kan du hjælpe?
Option Explicit
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 = 5 To 26  'data in rows 2-4 Rem Get the email address
      Email = Cells(r, 3)
    If Cells(r, 3) > "" Then
        bygMail r
  '  Else
  '      Cells(r, 7).Interior.ColorIndex = 3
       
    End If
  Next r
End Sub
Private Sub bygMail(r)
  Dim mailThis As Outlook.MailItem
  Dim MSG As String
  Dim Email As String
  Dim Subj As String
  Dim Disk As String, Filnavn As String
  Dim x As Long
  Disk = Cells(2, 6) & Format(Cells(2, 7), "dddd") & "\"
  ChDir Disk
  Filnavn = ".pdf"

  Set mailThis = CreateItem(olMailItem)
  Email = Cells(r, 3)
  '      Message subject Format(Cells(r, 3), "hh:mm:ss")
  If (Cells(r, 18)) <> "" Then
        Subj = "Rådighedstid " & "Fra " & Format(Cells(r, 9), "hh:mm") & " Til " & Format(Cells(r, 10), "hh:mm") & " Rådighedstid " & "Fra " & Format(Cells(r, 18), "hh:mm") & " Til " & Format(Cells(r, 19), "hh:mm")
  Else
        Subj = "1. tur skal køres " & "kl. " & Format(Cells(r, 10), "hh:mm  ") & "Fra " & Format(Cells(r, 13), "") & "        Sluttid " & Format(Cells(r, 11), "hh:mm  ") & "" & Format(Cells(r, 15), "")
  End If
 
  '      Compose the message
 
  MSG = MSG & "Hej  " & Cells(r, 4) & vbCrLf & vbCrLf
    If (Cells(r, 6)) <> "" Then
      MSG = MSG & Cells(r, 6) & vbCrLf & vbCrLf
    End If
  MSG = MSG & "Du har fået: " & vbCrLf & vbCrLf

 
 
  Select Case (Cells(r, 9))
      Case 1 To 35
        MSG = MSG & "HURLØB nr. " & Cells(r, 9) & vbCrLf & vbCrLf '& "  Rådighedstid fra:  " & Format(Cells(r, 10), "hh:mm") & " Til:  " & Format(Cells(r, 11), "hh:mm") & vbCrLf & vbCrLf & " " & Format(Cells(r, 12), "hh:mm") & " " & Cells(r, 13) & " " & Format(Cells(r, 14), "hh:mm") & " " & Cells(r, 15) & "" & Cells(r, 16) & vbCrLf & vbCrLf
        mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now(), "mm") & Format(Now() + 1, "dd") & Cells(2, 10) & Cells(r, 9) & "KV" & Filnavn
        mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now(), "mm") & Format(Now() + 1, "dd") & Cells(2, 10) & Cells(r, 9) & "KL" & Filnavn
      Case Else
  End Select
 
  Select Case (Cells(r, 17))
        Case 1 To 35
        MSG = MSG & "Og" & vbCrLf & vbCrLf
        MSG = MSG & "HURLØB " & Cells(r, 16) & "Rådighedstid " & Format(Cells(r, 17), "hh:mm") & " " & Format(Cells(r, 18), "hh:mm") & " Fra " & Format(Cells(r, 19), "hh:mm") & " " & Cells(r, 20) & " Til " & Format(Cells(r, 21), "hh:mm") & " " & Cells(r, 22) & " " & Cells(r, 23) & vbCrLf & vbCrLf
        mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now(), "mm") & Format(Now() + 1, "dd") & Cells(2, 9) & Cells(r, 16) & "KV" & Filnavn
        mailThis.Attachments.Add Disk & Format(Now(), "yyyy") & Format(Now(), "mm") & Format(Now() + 1, "dd") & Cells(2, 9) & Cells(r, 16) & "KL" & Filnavn
      Case Else
  End Select
 
  For x = 1 To 1
 
     
        If (Cells(5, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(5, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(5, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(5, 10), "hh:mm") & vbCrLf
        End If

        If (Cells(6, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(6, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(6, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(6, 10), "hh:mm") & vbCrLf
        End If
             
        If (Cells(7, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(7, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(7, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(7, 10), "hh:mm") & vbCrLf
        End If
       
               
        If (Cells(8, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(8, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(8, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(8, 10), "hh:mm") & vbCrLf
        End If

        If (Cells(9, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(9, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(9, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(9, 10), "hh:mm") & vbCrLf
        End If
             
        If (Cells(10, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(10, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(10, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(10, 10), "hh:mm") & vbCrLf
        End If
       
        If (Cells(11, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(11, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(11, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(11, 10), "hh:mm") & vbCrLf
        End If

        If (Cells(12, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(12, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(12, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(12, 10), "hh:mm") & vbCrLf
        End If
             
        If (Cells(13, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(13, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(13, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(13, 10), "hh:mm") & vbCrLf
        End If
       
        If (Cells(14, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(14, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(14, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(14, 10), "hh:mm") & vbCrLf
        End If

        If (Cells(15, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(15, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(15, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(15, 10), "hh:mm") & vbCrLf
        End If
             
        If (Cells(16, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(16, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(16, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(16, 10), "hh:mm") & vbCrLf
        End If
       
        If (Cells(17, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(17, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(17, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(17, 10), "hh:mm") & vbCrLf
        End If

        If (Cells(18, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(18, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(18, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(18, 10), "hh:mm") & vbCrLf
        End If
             
        If (Cells(19, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(19, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(19, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(19, 10), "hh:mm") & vbCrLf
        End If
       
        If (Cells(20, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(20, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(20, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(20, 10), "hh:mm") & vbCrLf
        End If

        If (Cells(21, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(21, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(21, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(21, 10), "hh:mm") & vbCrLf
        End If
             
        If (Cells(22, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(22, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(22, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(22, 10), "hh:mm") & vbCrLf
        End If
       
        If (Cells(23, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(23, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(23, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(23, 10), "hh:mm") & vbCrLf
        End If

        If (Cells(24, 2)) <> "" Then
        MSG = MSG & vbCrLf & "Løb  "
        MSG = MSG & Cells(24, 1)
        MSG = MSG & " Køres af:  "
        MSG = MSG & Cells(24, 2)
        MSG = MSG & "  med 1.tur kl:  "
        MSG = MSG & Format(Cells(24, 10), "hh:mm") & vbCrLf
        End If
       
        MSG = MSG & "" & vbCrLf & vbCrLf
        MSG = MSG & "Idag: " & vbCrLf & vbCrLf

     
        If (Cells(19, 26)) <> "" Then
        MSG = MSG & Cells(19, 26) & vbCrLf
        End If
        If (Cells(20, 26)) <> "" Then
        MSG = MSG & Cells(20, 26) & vbCrLf
        End If
       
        If (Cells(21, 26)) <> "" Then
        MSG = MSG & Cells(21, 26) & vbCrLf
        End If
        If (Cells(22, 26)) <> "" Then
        MSG = MSG & Cells(22, 26) & vbCrLf
        End If
        If (Cells(23, 26)) <> "" Then
        MSG = MSG & Cells(23, 26) & vbCrLf
        End If
        If (Cells(24, 26)) <> "" Then
        MSG = MSG & Cells(24, 26) & vbCrLf
        End If
       
       
        MSG = MSG & "Din rådighedstid starter ca dagens timetal trukket fra sluttiden. Spontanture kan forekomme!!" & vbCrLf
       
       
        If (Cells(1, 3)) <> "" Then
        MSG = MSG & vbCrLf & "Med Venlig Hilsen" & vbCrLf
        MSG = MSG & Cells(1, 3) & vbCrLf
        Else
        MSG = MSG & vbCrLf & "Med Venlig Hilsen" & vbCrLf
        MSG = MSG & "Vagten" & vbCrLf
        End If
       
       
       
       
       
        If Application.Wait(Now + TimeValue("0:00:02")) Then
        Cells(r, 7) = "X"
        End If

  Next
  mailThis.Recipients.Add Email
  mailThis.Subject = Subj
  mailThis.Body = MSG
  mailThis.Send 'Send mailen med det samme!!
'  mailThis.Save 'Gem mailen i kladder. Men hvis outlook er lukket bliver de lavt i inbox!!
'  mailThis.Display

End Sub
Avatar billede sjokoman Juniormester
04. september 2007 - 19:55 #4
Hvis jeg har læst rigtigt, er det felt Q5 osv og det er tt.mm
Avatar billede sjokoman Juniormester
04. september 2007 - 21:29 #5
Der er i linjen med (r,9) at fejlen ligger, jeg bruger ikke den med (r,16). Den er formateret til standard.
mvh Johnny
Avatar billede sjokoman Juniormester
07. september 2007 - 04:39 #6
Lukker da jeg har fået fjernet bogstavet!
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Excel kurser for alle niveauer og behov – find det kursus, der passer til dig

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester