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

Automatische email met csv bijlage versturen

Status
Niet open voor verdere reacties.

toverkamp

Gebruiker
Lid geworden
11 sep 2006
Berichten
403
Beste forumleden,

In onderstaande VBA code wordt met 1 druk op de knop een email verstuurd met als bijlage een bestand. Dit bestand moet als CSV bestand worden verstuurd.

Ik sla het bestand al op als CSV (zie blauwe tekst), maar dit houdt in dat je achter de naam .csv zet en het bestand nog steeds opslaat als MS Office Excel-werkmap.

Opslaan als moet dus CSV zijn. Hoe moet ik onderstaande code aanpassen?

Code:
Option Explicit
 
Const EMBED_ATTACHMENT As Long = 1454

Const stPath As String = "[COLOR="red"]Locatie[/COLOR]"

Const stSubject As String = "[COLOR="red"]Onderwerp[/COLOR]"

Const vaMsg As Variant = "[COLOR="red"]beschrijving[/COLOR]"

'stuur CC Const vaCopyTo As Variant = "[COLOR="red"]emailadres[/COLOR]"

Sub Send_Active_Sheet()
'verzend email naar [COLOR="red"]naam[/COLOR]

  Dim stFileName As String
  Dim vaRecipients As Variant
 
  Dim noSession As Object
  Dim noDatabase As Object
  Dim noDocument As Object
  Dim noEmbedObject As Object
  Dim noAttachment As Object
  Dim stAttachment As String
 
  'Copy the active sheet to a new temporarily workbook.
  With Blad23
    .Copy
    stFileName = "[COLOR="red"]omschrijving document[/COLOR]" & .Range("H2").Value
  End With
 
  stAttachment = stPath & "\" & stFileName & "[COLOR="blue"].csv[/COLOR]"
 
  'Save and close the temporarily workbook.
  With ActiveWorkbook
    .SaveAs stAttachment
    .Close
  End With
 
'Verzend email naar
  vaRecipients = VBA.Array("[COLOR="red"]emailadres[/COLOR]")

 
  'Instantiate the Lotus Notes COM's Objects.
  Set noSession = CreateObject("Notes.NotesSession")
  Set noDatabase = noSession.GETDATABASE("", "")
 
  'If Lotus Notes is not open then open the mail-part of it.
  If noDatabase.IsOpen = False Then noDatabase.OPENMAIL
 
  'Create the e-mail and the attachment.
  Set noDocument = noDatabase.CreateDocument
  Set noAttachment = noDocument.CreateRichTextItem("stAttachment")
  Set noEmbedObject = noAttachment.EmbedObject(EMBED_ATTACHMENT, "", stAttachment)
 
  'Add values to the created e-mail main properties.
  With noDocument
    .Form = "Memo"
    .SendTo = vaRecipients
    .CopyTo = vaCopyTo
    .Subject = stSubject
    .Body = vaMsg
    .SaveMessageOnSend = True
    .PostedDate = Now()
    .Send 0, vaRecipients
  End With
 
  'Delete the temporarily workbook.
  Kill stAttachment
 
  'Release objects from memory.
  Set noEmbedObject = Nothing
  Set noAttachment = Nothing
  Set noDocument = Nothing
  Set noDatabase = Nothing
  Set noSession = Nothing
 
  MsgBox "De e-mail is succesvol verzonden naar [COLOR="red"]naam[/COLOR]", vbInformation
 
End Sub
 
Code:
stAttachment = stPath & "\" & stFileName & ".csv"
 
  'Save and close the temporarily workbook.
  With ActiveWorkbook
    .SaveAs stAttachment[B][COLOR="red"], FileFormat:=xlCSV[/COLOR][/B]    .Close
  End With

Met vriendelijke groet,


Roncancio
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan