Mijn vraag
Ik zit met het volgende. Heb over het internet gezocht en 2 gevonden macro's gecombineerd om een mail op te slaan die ik heb geselecteerd (dus hoeft niet per se open te zijn) in een bepaalde locatie.
Het enige wat men nog hoeft te doen, is een projectnummer in te vullen en aan te geven of het een ingekomen mails is of uitgaand.
Relevante software en hardware die ik gebruik
Office 365
Wat ik al gevonden of geprobeerd heb
Ik heb dus onderstaande macro, die bestaat uit 2 gevonden macro's. Probleem is echter dat hij op de vetgedrukte regel een error geeft. En ik snap niet waarom.
Private Sub CommandButton1_Click()
Dim olMail As MailItem
Dim olNs As NameSpace
Dim olApp As Outlook.Application
Dim selection As selection
Set olApp = ThisOutlookSession.Application
Set olNs = olApp.GetNamespace("MAPI")
Set selection = olApp.ActiveExplorer.selection
Set olMail = selection(1)
onderwerp = olMail.Subject
Set olMail = Nothing
Set olNs = Nothing
Set selection = Nothing
Set olApp = Nothing
'-----------------------------
Dim Item As Object
Const olMsg As Long = 3
Dim m As MailItem
Dim savePath As String
projectnr = TextBox1.Value
If OptionButton1.Value = True Then
richting = "Ingekomen\"
ElseIf OptionButton2.Value = True Then
richting = "Uitgaand\"
Else
MsgBox ("Selecteer ingekomen of uitgaande mail!")
Exit Sub
End If
Set m = Item
savePath = "V:\" & projectnr & "\Correspondentie\e-mail berichten\" & richting '## Modify as needed
savePath = savePath & Format(Now(), "yyyy-mm-dd") & " " & onderwerp
savePath = savePath & ".msg"
On Error GoTo Fout
MsgBox savePath
m.SaveAs savePath, olMsg
MsgBox ("Mail succesvol opgeslagen!")
UserForm1.TextBox1.Value = ""
OptionButton1.Value = False
OptionButton2.Value = False
UserForm1.Hide
Exit Sub
Fout:
MsgBox ("Er is iets fouts gegaan bij het opslaan! Probeer het nog een keer!")
End Sub
Ik zit met het volgende. Heb over het internet gezocht en 2 gevonden macro's gecombineerd om een mail op te slaan die ik heb geselecteerd (dus hoeft niet per se open te zijn) in een bepaalde locatie.
Het enige wat men nog hoeft te doen, is een projectnummer in te vullen en aan te geven of het een ingekomen mails is of uitgaand.
Relevante software en hardware die ik gebruik
Office 365
Wat ik al gevonden of geprobeerd heb
Ik heb dus onderstaande macro, die bestaat uit 2 gevonden macro's. Probleem is echter dat hij op de vetgedrukte regel een error geeft. En ik snap niet waarom.
Private Sub CommandButton1_Click()
Dim olMail As MailItem
Dim olNs As NameSpace
Dim olApp As Outlook.Application
Dim selection As selection
Set olApp = ThisOutlookSession.Application
Set olNs = olApp.GetNamespace("MAPI")
Set selection = olApp.ActiveExplorer.selection
Set olMail = selection(1)
onderwerp = olMail.Subject
Set olMail = Nothing
Set olNs = Nothing
Set selection = Nothing
Set olApp = Nothing
'-----------------------------
Dim Item As Object
Const olMsg As Long = 3
Dim m As MailItem
Dim savePath As String
projectnr = TextBox1.Value
If OptionButton1.Value = True Then
richting = "Ingekomen\"
ElseIf OptionButton2.Value = True Then
richting = "Uitgaand\"
Else
MsgBox ("Selecteer ingekomen of uitgaande mail!")
Exit Sub
End If
Set m = Item
savePath = "V:\" & projectnr & "\Correspondentie\e-mail berichten\" & richting '## Modify as needed
savePath = savePath & Format(Now(), "yyyy-mm-dd") & " " & onderwerp
savePath = savePath & ".msg"
On Error GoTo Fout
MsgBox savePath
m.SaveAs savePath, olMsg
MsgBox ("Mail succesvol opgeslagen!")
UserForm1.TextBox1.Value = ""
OptionButton1.Value = False
OptionButton2.Value = False
UserForm1.Hide
Exit Sub
Fout:
MsgBox ("Er is iets fouts gegaan bij het opslaan! Probeer het nog een keer!")
End Sub