Saving Send emails to a folder on the server

It's working here - but it is saved as an unsent message. If you want to save it after it was sent, you need to use the itemadd macro - after adding it to thisoutlooksession, click in application startup and click run to kick start it.


Code:
Private WithEvents objSentItems As Items

Private Sub Application_Startup()
Dim objSent As Outlook.MAPIFolder
Set objNS = Application.GetNamespace("MAPI")
Set objSentItems = objNS.GetDefaultFolder(olFolderSentMail).Items
Set objNS = Nothing
End Sub
 
Private Sub objSentItems_ItemAdd(ByVal oMail As Object)

 Dim sPath As String
  Dim dtDate As Date
  Dim sName As String
  Dim StrFolderpath As String
  Dim StrUserPath As Variant

'Defaults to Documents folder
'get the function at http://slipstick.me/u1a2d
If oMail.MessageClass = "IPM.Note" Then

StrUserPath = "C:\Users\JennyWren\OneDrive - Slipstick Systems\Documents\"
StrFolderpath = BrowseForFolder(StrUserPath)

If StrFolderpath = "False" Then
      Cancel = True
      Exit Sub
  End If
 
  sName = oMail.Subject
  ReplaceCharsForFileName sName, "-"
 
  dtDate = oMail.ReceivedTime
  sName = Format(dtDate, "ddmmyyyy", vbUseSystemDayOfWeek, _
    vbUseSystem) & Format(dtDate, "-hhnnss", _
    vbUseSystemDayOfWeek, vbUseSystem) & "-" & sName & ".msg"
     
  sPath = StrFolderpath & "\"
  Debug.Print sPath & sName
  oMail.SaveAs sPath & sName, olMSG
 
  End If
 
End Sub

Private Sub ReplaceCharsForFileName(sName As String, _
  sChr As String _
)
  sName = Replace(sName, "'", sChr)
  sName = Replace(sName, "*", sChr)
  sName = Replace(sName, "/", sChr)
  sName = Replace(sName, "\", sChr)
  sName = Replace(sName, ":", sChr)
  sName = Replace(sName, "?", sChr)
  sName = Replace(sName, Chr(34), sChr)
  sName = Replace(sName, "<", sChr)
  sName = Replace(sName, ">", sChr)
  sName = Replace(sName, "|", sChr)
End Sub

Function BrowseForFolder(Optional OpenAt As Variant) As Variant
  Dim ShellApp As Object
  Set ShellApp = CreateObject("Shell.Application"). _
 BrowseForFolder(0, "Please choose a folder", 0, OpenAt)
 
 On Error Resume Next
    BrowseForFolder = ShellApp.self.Path
 On Error GoTo 0
 
 Set ShellApp = Nothing
    Select Case Mid(BrowseForFolder, 2, 1)
        Case Is = ":"
            If Left(BrowseForFolder, 1) = ":" Then GoTo Invalid
        Case Is = "\"
            If Not Left(BrowseForFolder, 1) = "\" Then GoTo Invalid
        Case Else
            GoTo Invalid
    End Select
 Exit Function
 
Invalid:
    BrowseForFolder = False
End Function
 
Hi Diane
I set up Outlook in Startup but and it saved the email after sending. Thx very much for this but,
1. My outlook is always on so I can't kick start it. I never shut it down as I work remotely from time to time and need to RDP to my PC
2. I need the headers of the send email all so to be saved.
 
1. It should always run once started - if it errors, it will need restarted.

I add this macro to a button to kick start it when I think it might not be working-
Code:
Sub RunStart()
 Call Application_Startup
 MsgBox "App Start Started"
End Sub

2. As in the internet headers? They should be on the message. Open it then File > Properties.
 
1. It should always run once started - if it errors, it will need restarted.

I add this macro to a button to kick start it when I think it might not be working-
Code:
Sub RunStart()
 Call Application_Startup
 MsgBox "App Start Started"
End Sub

2. As in the internet headers? They should be on the message. Open it then File > Properties.
Thx Diane 😀
 
1. It should always run once started - if it errors, it will need restarted.

I add this macro to a button to kick start it when I think it might not be working-
Code:
Sub RunStart()
 Call Application_Startup
 MsgBox "App Start Started"
End Sub

2. As in the internet headers? They should be on the message. Open it then File > Properties.
Hi Diane where did you put your kick start button?
 
Hi Diane where did you put your kick start button?
Hi Diane where did you put your kick start button?
Hi Diane
This just happened to me, selecting the wrong dir, CommercialClients instead of PersonalClients. The popup dialog file tree
Clients
>CommercialClients
>PersonalClients

So I click on Clients again thinking that it will bring me back to file tree above but can't
Is there away to accomplish this
 
Hi Diane
I copied the code to my admin PC. Digital Signed the code. Marco settings is set to Digitally Signed macros, disabled all others and saved the project.

When I went back into Outlook I get a message that Macros are disabled. The Digital Signature is still active under vba editor/digital signature. Does have perhaps to do with references?
 
Hi Diane after my fiddling. I have a look at Coms.Add Ins, Disabled Items. Both PCs setup are the same. Only difference is that the Admin PC has Office 2019 on it as mine has 2021.

On the Admin PC the Digital Certificate is accepted. Reason knowing that is when I select the Certificate Remove and reselect it, save all and restart Outook 2019 message box pop up asking if trust the Certificate on which I click yes.

Then I send and email but no popup dialog as on on my Outlook 2021

Clients
>ComercialClients
>PersonalClients

I run debug but no errors in immediate window.

All is precisely Setup as on my Outlook 2021.
Can this be a setting that I miss.
 
Might this be the problem for dialog box not showing?
Microsoft Windows common controls?
 
Hi Diane
This just happened to me, selecting the wrong dir, CommercialClients instead of PersonalClients. The popup dialog file tree
Clients
>CommercialClients
>PersonalClients

So I click on Clients again thinking that it will bring me back to file tree above but can't
Is there away to accomplish this
You are still in the folder picker dialog? It's working as expected here - I can select a folder and then choose a different folder.
 
You are still in the folder picker dialog? It's working as expected here - I can select a folder and then choose a different folder.
Diane
I can't see the folder picker dialog. If it's there then it might be in the back ground or something but it's not visible. I minimize all the open programs but still no folder picker. Maybe a setting in Outlook about popups?
This is Outlook 2019 with Windows 10 Pro
 
Diane I this

Dim sPath As String
Dim dtDate As Date
Dim sName As String
Dim StrFolderpath As String
Dim StrUserPath As Variant

Msgbox "macro is running"
 
Diane Iike this

Dim sPath As String
Dim dtDate As Date
Dim sName As String
Dim StrFolderpath As String
Dim StrUserPath As Variant

Msgbox "macro is running"
Hi Diane
Macro is not running.
I do not understand as this setup is exactly the same as the other to PCs
 
Hi Diane
Macro is not running.
I do not understand as this setup is exactly the same as the other to PCs
I found the below as a disabled item on my other pc but not on this one where I struggle to get the code running.
Hi Diane
Macro is not running.
I do not understand as this setup is exactly the same as the other to PCs
I found on my pc where the code is running perfectly in Outlook that this item below is disabled but not on the pc in struggle with the vba code to run in Outlook. How do make this an disabled item as on my other pc.
 
I found this under disabled add ins items in Outlook 2021 that run the VBA code

1000099853.jpg

As I can't find nothing under Disabled Add Ins items in Outlook 2019 (other PC). Can this prevent the code form running?

And is so how do I add it under Disabled Add Ins items.
 
Hi Diane
I was wondering, appart from that still struggle to get SaveMessage code to work in Outlook 2019. If it is possible, can the popup dialog folder picker be restricted to 1 pc (which I remotely connect to) as I use IMAP email account.

So if I send emails from my android tablet then when I get back to the office there is a few dialog file pickers boxes open. Is there away around this.
 
Ok I run Outlook 2019 in safe mode (Outlook.exe /safe)
I then run Debug to cursor and get the following File Picker Dialog called Capture instead of the Correct Dialog (please see attachments). This happens in safe mode. In normal mode no popup dialog

Capture.JPG


Correct DialogJPG.JPG
 
I found this under disabled add ins items in Outlook 2021 that run the VBA code

View attachment 4266
As I can't find nothing under Disabled Add Ins items in Outlook 2019 (other PC). Can this prevent the code form running?

And is so how do I add it under Disabled Add Ins items.
I don't know what add-in that one is - but as long as the VB add-in is loaded, the macro will work.

I'm guessing klavplg is part of the parent apps name - maybe stands for klav plugin? Beyond that, I don't know what it is or what klav could be.
 
Hi Diane
I was wondering, appart from that still struggle to get SaveMessage code to work in Outlook 2019. If it is possible, can the popup dialog folder picker be restricted to 1 pc (which I remotely connect to) as I use IMAP email account.

So if I send emails from my android tablet then when I get back to the office there is a few dialog file pickers boxes open. Is there away around this.
Ah... its coming up when you sync, because the macro watches for items to be added to the folder. I'll need to think about how to get past that.
 
Similar threads
Thread starter Title Forum Replies Date
N Saving .msg as sent item on send Outlook VBA and Custom Forms 1
Rupert Dragwater Background colors not saving in Outlook 365 Using Outlook 15
R Saving Emails and Attachments as .msg file Using Outlook 3
CWM330 Saving Data: Don't check certain folders Using Outlook 2
M Saving emails using Visual Basic - Selecting folder with msoFileDialogFolderPicker Outlook VBA and Custom Forms 6
D Outlook 2016 Outlook not saving Sent Items Using Outlook 4
I Error saving screenshots in a custom form in outlook 2016, outlook 365 - ok in outlook 2013, outlook 2010 Outlook VBA and Custom Forms 5
I Saving attachments from multiple emails and updating file name Outlook VBA and Custom Forms 0
M Adding Subject to this Link-Saving VBA Outlook VBA and Custom Forms 5
L Attachment saving and tracking - PLEASE help! Outlook VBA and Custom Forms 5
D Saving Selected Emails as PDF and saving Attachments Outlook VBA and Custom Forms 6
B Saving items under a folder Using Outlook 3
R Quick Access view in File Explorer when saving attachments Using Outlook 0
N Saving And Deleting Outlook Attachments with Unknown Error Message Outlook VBA and Custom Forms 1
V Saving attachment from outlook in My Documents Outlook VBA and Custom Forms 14
M Dialog called up multiple times when saving emails from macro Outlook VBA and Custom Forms 2
A saving attachement to folder named the same as rule name Outlook VBA and Custom Forms 0
T Saving all email to file folder in Windows Using Outlook 2
J Saving attachments from specific sender (phone number) to specific folder on hard drive Using Outlook 3
C Saving Outlook attachments and links to attachments with VBA Outlook VBA and Custom Forms 2
Kevin H Remotely saving emails Using Outlook 1
R Outlook 2010 Modify Style "Do not check spelling or grammar" not saving Outlook VBA and Custom Forms 0
R Outlook Office 365 not saving addresses Using Outlook 0
A Keep color categories when saving vCards Using Outlook 1
P Saving All Messages to the Hard Drive Using VBA Outlook VBA and Custom Forms 5
e_a_g_l_e_p_i question about saving my .pst so I can import it to my Outlook after I build a new system Using Outlook 10
S Editing an email with notes and saving it for record using Macro Outlook VBA and Custom Forms 3
O Saving Attachments to folder on disk and adding Initials to end of file name Outlook VBA and Custom Forms 9
J Outlook 2013 crashes saving VBA & clicking tools | digital signature Outlook VBA and Custom Forms 1
bifjamod Saving sent email to specific folder based on category with wildcard Outlook VBA and Custom Forms 1
erichamion Changes to meeting body not properly saving Outlook VBA and Custom Forms 4
A ItemAdd on Imap Folder get endless loop after saving item Using Outlook 5
T Saving Outlook 2010 email with attachments but read the email without Outlook Using Outlook 2
T From Field Blank when saving to folder other than Sent items Using Outlook 2
L Outlook DST (Daylight Saving Time) problem Using Outlook 0
F Using Outlook 2007 as an IMAP Mail Station Without Saving Data Locally Using Outlook 2
E Saving Changes To Edited E-Mail Received Message Using Outlook 0
D File Lock issue when saving message from Outlook to new folder Using Outlook 1
D Remove extension while saving attachments Using Outlook 1
K Printing & Saving Outlook Contacts Using Outlook 3
S Not saving attachments in the Sent Folder Using Outlook 2
S trouble with Outlook 2010 saving sent emails Using Outlook 2
D Saving outlook emails in html and attachments Using Outlook 4
W Default Saving a message as text Using Outlook 2
R Outlook 2007 QAT buttons not saving Using Outlook 2
C Exchange 2003 - Outlook 2003 - Calendar entries saving over each other Using Outlook 2
J Saving Published Outlook Form as msg Using Outlook 1
J Saving recent colors used for fonts in an email? Using Outlook 1
B How to choose which contacts folder to use when saving contacts? Using Outlook 1
J Saving Incoming & Outgoing Outlook 2010 Email Locally with IMAP Using Outlook 2

Similar threads

Back
Top