wesleyken007
Gebruiker
- Lid geworden
- 20 okt 2020
- Berichten
- 10
Allen,
Ik geraak er niet uit.
Ik heb 2 mailaccounts (Privé en 1 van Ouderraad school) in Office Outlook
Voor een wedstrijd zend ik vanuit excel een mail met bijhorende documenten en werkt perfect.
Echter wordt dit verzonden vanuit mijn privé mailadres.
Bedoeling is dat dit wordt verstuurd vanuit mailadres Ouderraad.
Ik heb dan ook onderstaande code gebruikt om te kijken welke nr mijn accounts hebben wat perfect werkt en geeft aan dat Ouderraad nr 2 is:
Sub Which_Account_Number()
Dim OutApp As Object
Dim I As Long
Set OutApp = CreateObject("Outlook.Application")
For I = 1 To OutApp.Session.Accounts.Count
MsgBox OutApp.Session.Accounts.Item(I) & " : This is account number " & I
Next I
End Sub
So far so good...
Echter als ik dit dan verwerk in mijn code om de mail te versturen, blijft hij mijn privé adres gebruiken.
HELP?
Dim Bestand, Boekje, Kinder, Foto, Tekst As String
Dim OutApp As Object
Dim OutMail As Object
Dim OutAccount As Object
Bestand = Environ("TEMP") & "" & ActiveSheet.Name & ".pdf"
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=Bestand
Boekje = "C:\Users\wesle\Documents\Wandelrally\Boekje wandelrally 2020.pdf"
Foto = "C:\Users\wesle\Documents\Wandelrally\Fotoronde wandelrally 2020.pdf"
Kinder = "C:\Users\wesle\Documents\Wandelrally\Kinderbingo.pdf"
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Set OutAccount = OutApp.Session.Accounts.Item(2)
Tekst = "Beste, " & Range("M3").Value & vbCrLf & _
"" & vbCrLf & _
"Hartelijk dank voor uw inschrijving voor onze allereerste wandelrally." & vbCrLf & _
"" & vbCrLf & _
"In bijlage kan u het wandelrally-boekje, de foto's, de kinderbingo en uw uniek antwoordformulier terugvinden." & vbCrLf & _
"U kan dit formulier ingevuld mailen naar mail@mail.be of meegeven via de boekentas ten laatste op maandag 29/2/2021." & vbCrLf & _
"" & vbCrLf & _
"Wij wensen u alvast veel succes en veel wandelgenot." & vbCrLf & _
"" & vbCrLf & _
"Met vriendelijke groeten," & vbCrLf & _
"Ouderraad"
With OutMail
.To = Range("Q7").Value
.CC = ""
.BCC = ""
.Subject = "Bevestiging inschrijving Ouderraad."
.Body = Tekst
.Attachments.Add Boekje
.Attachments.Add Foto
.Attachments.Add Kinder
.Attachments.Add Bestand
.Send
End With
Kill Bestand
End Sub
Ik geraak er niet uit.
Ik heb 2 mailaccounts (Privé en 1 van Ouderraad school) in Office Outlook
Voor een wedstrijd zend ik vanuit excel een mail met bijhorende documenten en werkt perfect.
Echter wordt dit verzonden vanuit mijn privé mailadres.
Bedoeling is dat dit wordt verstuurd vanuit mailadres Ouderraad.
Ik heb dan ook onderstaande code gebruikt om te kijken welke nr mijn accounts hebben wat perfect werkt en geeft aan dat Ouderraad nr 2 is:
Sub Which_Account_Number()
Dim OutApp As Object
Dim I As Long
Set OutApp = CreateObject("Outlook.Application")
For I = 1 To OutApp.Session.Accounts.Count
MsgBox OutApp.Session.Accounts.Item(I) & " : This is account number " & I
Next I
End Sub
So far so good...
Echter als ik dit dan verwerk in mijn code om de mail te versturen, blijft hij mijn privé adres gebruiken.
HELP?
Dim Bestand, Boekje, Kinder, Foto, Tekst As String
Dim OutApp As Object
Dim OutMail As Object
Dim OutAccount As Object
Bestand = Environ("TEMP") & "" & ActiveSheet.Name & ".pdf"
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=Bestand
Boekje = "C:\Users\wesle\Documents\Wandelrally\Boekje wandelrally 2020.pdf"
Foto = "C:\Users\wesle\Documents\Wandelrally\Fotoronde wandelrally 2020.pdf"
Kinder = "C:\Users\wesle\Documents\Wandelrally\Kinderbingo.pdf"
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Set OutAccount = OutApp.Session.Accounts.Item(2)
Tekst = "Beste, " & Range("M3").Value & vbCrLf & _
"" & vbCrLf & _
"Hartelijk dank voor uw inschrijving voor onze allereerste wandelrally." & vbCrLf & _
"" & vbCrLf & _
"In bijlage kan u het wandelrally-boekje, de foto's, de kinderbingo en uw uniek antwoordformulier terugvinden." & vbCrLf & _
"U kan dit formulier ingevuld mailen naar mail@mail.be of meegeven via de boekentas ten laatste op maandag 29/2/2021." & vbCrLf & _
"" & vbCrLf & _
"Wij wensen u alvast veel succes en veel wandelgenot." & vbCrLf & _
"" & vbCrLf & _
"Met vriendelijke groeten," & vbCrLf & _
"Ouderraad"
With OutMail
.To = Range("Q7").Value
.CC = ""
.BCC = ""
.Subject = "Bevestiging inschrijving Ouderraad."
.Body = Tekst
.Attachments.Add Boekje
.Attachments.Add Foto
.Attachments.Add Kinder
.Attachments.Add Bestand
.Send
End With
Kill Bestand
End Sub