Mail opslaan in bepaalde map

Pagina: 1
Acties:

Vraag


  • JelleDJs
  • Registratie: Juni 2013
  • Laatst online: 09-10 16:56
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

Alle reacties


Acties:
  • 0 Henk 'm!

  • hihans
  • Registratie: Oktober 2019
  • Laatst online: 16-08-2021
Dan is het wel handig de error er bij te vermelden.

Acties:
  • 0 Henk 'm!

  • JelleDJs
  • Registratie: Juni 2013
  • Laatst online: 09-10 16:56
Fout 91 tijdens uitvoering:

Objectvariabele of blokvariabele With is niet ingesteld

Update: inmiddels heb ik wat dingen uitgeprobeerd en heb ik het werkend gekregen.

[ Voor 34% gewijzigd door JelleDJs op 28-02-2020 13:42 . Reden: Werkend gekregen ]