• Privacywetgeving
    Het is bij Helpmij.nl niet toegestaan om persoonsgegevens in een voorbeeld te plaatsen. Alle voorbeelden die persoonsgegevens bevatten zullen zonder opgaaf van reden verwijderd worden. In de vraag zal specifiek vermeld moeten worden dat het om fictieve namen gaat.

Datum in bijlage, Subject en Body

Status
Niet open voor verdere reacties.

jolly01

Gebruiker
Lid geworden
12 apr 2009
Berichten
486
Ron de Bruin heeft met zijn voorbeelden mij op het goede pad gebracht om sheets binnen excel te mailen met outlook.
Wat me nog niet goed lukt is de body en subject en de bijlage naar mijn wensen aan te passen.

Onderstaande zou ik graag in de email hebben staan:
Waarbij "xx-xx-xxxx" de huidige datum moet zijn.

Bijlage:

Dagvoorraad xx-xx-xxxx

Subject:
Dagvoorraad xx-xx-xxxx


Body:

Goedemorgen,

Hierbij de voorraadlijst d.d. xx-xx-xxxx.

Met vriendelijke groet,

Jan Jansen


Iemand een idee hoe ik Ron's code moet aanpassen zodat het bovenstaande in de bijlage , subject en body komt te staan?
 

Bijlagen

Nou is het gelukt de body te verfijnen met meerdere regels, met de code van Purrel

Code:
.Body = "Goedemorgen," & vbNewLine & _
                    " " & vbNewLine & _
                    "Hierbij de voorraadlijst van" & vbNewLine & _
                    "Met vriendelijke groet," & vbNewLine & _
                    " " & vbNewLine & _
                    "Jan Jansen" & vbNewLine

In de body wil ik naast "Hierbij de voorraadlijst van" de huidige datum.
Als ook in het excel attachment en het subject.
 
Code:
Sub Mail_ActiveSheet()
' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, Outlook 2010
    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim OutApp As Object
    Dim OutMail As Object

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    Set Sourcewb = ActiveWorkbook

    ' Next, copy the sheet to a new workbook.
    ' You can also use the following line, instead of using the ActiveSheet object,
   ' if you know the name of the sheet you want to mail :
    ' Sheets("Sheet5").Copy
    ActiveSheet.Copy
    Set Destwb = ActiveWorkbook

    ' Determine the Excel version, and file extension and format.
    With Destwb
        If Val(Application.Version) < 12 Then
            ' For Excel 2000-2003
            FileExtStr = ".xls": FileFormatNum = -4143
        Else
            ' For Excel 2007-2010, exit the subroutine if you answer
            ' NO in the security dialog that is displayed when you copy
            ' a sheet from an .xlsm file with macros disabled.
            If Sourcewb.Name = .Name Then
                With Application
                    .ScreenUpdating = True
                    .EnableEvents = True
                End With
                MsgBox "You answered NO in the security dialog."
                Exit Sub
            Else
                Select Case Sourcewb.FileFormat
                Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
                Case 52:
                    If .HasVBProject Then
                        FileExtStr = ".xlsm": FileFormatNum = 52
                    Else
                        FileExtStr = ".xlsx": FileFormatNum = 51
                    End If
                Case 56: FileExtStr = ".xls": FileFormatNum = 56
                Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
                End Select
            End If
        End If
    End With

    ' You can use the following statements to change all cells in the
   ' worksheet to values.
    '    With Destwb.Sheets(1).UsedRange
    '        .Cells.Copy
    '        .Cells.PasteSpecial xlPasteValues
    '        .Cells(1).Select
    '    End With
    '    Application.CutCopyMode = False

    ' Save the new workbook, mail, and then delete it.
    TempFilePath = Environ$("temp") & "\"
    TempFileName = "Dagvoorraad " & Format(Date, "dd-mm-yyyy")

    Set OutApp = CreateObject("Outlook.Application")
    
    Set OutMail = OutApp.CreateItem(0)

    With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, _
                FileFormat:=FileFormatNum
        On Error Resume Next
       ' Change the mail address and subject in the macro before
       ' running the procedure.
        With OutMail
            .To = "1@2.com"
            .CC = "3@4.nl;5@6.nl"
            .BCC = ""
            .Subject = "Dagvoorraad " & Format(Date, "dd-mm-yyyy")
            .Body = "Goedemorgen," & vbNewLine & _
                    " " & vbNewLine & _
                    "Hierbij de voorraadlijst van " & Format(Date, "dd-mm-yyyy") & vbNewLine & _
                    "Met vriendelijke groet," & vbNewLine & _
                    " " & vbNewLine & _
                    "Jan Jansen" & vbNewLine
            .Attachments.Add Destwb.FullName
            ' You can add other files by uncommenting the following statement.
            '.Attachments.Add ("C:\test.txt")
            ' In place of the following statement, you can use ".Display" to
            ' display the mail.
            .display '.Send
        End With
        On Error GoTo 0
        .Close SaveChanges:=False
    End With

    ' Delete the file after sending.
    Kill TempFilePath & TempFileName & FileExtStr

    Set OutMail = Nothing
    Set OutApp = Nothing

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub
 
Bedankt Rudi !:thumb:

Weer een stapje verder.

Kan je aangeven hoe ik de opmaak van de body verander in Verdana 11 punten?
 
Dan zal je ipv Body gbebruik moeten maken van HtmlBody
 
Bedankt voor je input. Ik heb er nog niet naar kunnen kijken. Intussen zet ik de vraag op opgelost.
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan