• 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.

Via macro het geexporteerde pdf bestand versturen via mail

Status
Niet open voor verdere reacties.

edsel_nl

Gebruiker
Lid geworden
24 okt 2006
Berichten
72
Heb een eerdere vraag wat ingekort:
Het probleem ligt als volgt als ik de onderstaande code gebruik start het mailprogramma met als bijlage het excel bestand. Terwijl ik juist het aangemaakte pdf bestand wil versturen. Wie weet een oplossing?
Code:
Sub Bestelling_versturen()
' Rijen waar aantal is 0 verbergen
Application.ScreenUpdating = False
For rij = 16 To 58
If Cells(rij, 10) = 0 Then Rows(rij).EntireRow.Hidden = True
Next rij

' Bestand exporteren als PDF
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\Default\" & Range("H2") & " " & Range("C6") & ".pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
       
' Verzenden via mail van het PDF bestand.
' Met de mogelijkheid zelf nog wat te veranderen in het bericht.
Application.Dialogs(xlDialogSendMail).Show _
arg1:=Range("A7"), _
arg2:="Bestelling " & Range("C6")

' Maakt alles weer zichtbaar.
Cells.EntireRow.Hidden = False
[C6].Select
Application.ScreenUpdating = True
End Sub

Voorbeeld bestand zie bijlage. Alvast bedankt :thumb:
 

Bijlagen

Heb het probleem voor een deel opgelost... Nu rest alleen nog de vraag hoe ik het automatisch gemaakte mailtje dat is geplaatst in de uit box van Outlook automatisch verstuur. Want nu wordt het mailtje wel in de uit box gezet maar Outlook zelf start niet op waardoor het mailtje pas verstuurt wordt wanneer Oulook gestart wordt.
Code:
' Bestand exporteren als PDF
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\Default\" & Range("H2") & " " & Range("C6") & ".pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
       
' Verzenden via mail.
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
With OutMail
    .To = Range("C8")
    .CC = ""
    .BCC = ""
    .Subject = "Bestelling"
    .Body = "Met vriendelijke groet," & " " & Range("H9") & " " & "(Zie bijlage voor bestelling.)"
    .Attachments.Add "C:\Users\Default\" & Range("H2") & " " & Range("C6") & ".pdf"
    .send
End With
Set OutMail = Nothing
Set OutApp = Nothing
        
' Delete PDF file.
Kill "C:\Users\Default\" & Range("H2") & " " & Range("C6") & ".pdf"
Set OutMail = Nothing
Set OutApp = Nothing
 
Oplossing

Heb de oplossing! Met dank aan Emile! :thumb:

Code:
' Bestand exporteren als PDF
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\Default\" & Range("H2") & " " & Range("C6") & ".pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
       
' Verzenden via mail.
Err.Number = 0
On Error Resume Next
Set OutApp = GetObject(, "Outlook.Application")
If Err.Number > 0 Then
Set OutApp = CreateObject("Outlook.Application")
Err.Clear
End If
On Error GoTo 0
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
With OutMail
    .To = Range("C8")
    .CC = ""
    .BCC = ""
    .Subject = "Bestelling"
    .Body = "Met vriendelijke groet," & " " & Range("H9") & " " & "(Zie bijlage voor bestelling)"
    .Attachments.Add "C:\Users\Default\" & Range("H2") & " " & Range("C6") & ".pdf"
    .display
End With
Set OutMail = Nothing
Set OutApp = Nothing
        
' Delete PDF file.
Kill "C:\Users\Default\" & Range("H2") & " " & Range("C6") & ".pdf"
Set OutMail = Nothing
Set OutApp = Nothing
    
' Venster zegt .
MsgBox "Bestelling is verstuurt en opgeslagen in C:\Users\Default\Faxbestelling database\"
 
Laatst bewerkt:
Is het ook mogelijk om deze code te gebruiken in combinatie met een distributielijst in Outlook??
 
Zenden naar een distributielijst in outlook

Tuurlijk is dat mogelijk, plaats op de plek waar nu Naamloos staat de distributielijstnaam in zoals die staat in Outlook staat.

Code:
[COLOR="Yellow"]' Verzenden via mail.[/COLOR]
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
With OutMail
    .To = [COLOR="Red"]"Naamloos"[/COLOR]
    .CC = ""
    .BCC = ""
    .Subject = "Bestelling"
    .Body = "Met vriendelijke groet," & " " & Range("H9") & " " & "(Zie bijlage voor bestelling.)"
    .Attachments.Add "C:\Users\Default\"file.pdf"
    .send
End With
Set OutMail = Nothing
Set OutApp = Nothing
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan