JohanKotze
Senior Member
- OS Version(s)
- Windows
- Outlook version
- Outlook 2019 64-bit
- Email Account
- IMAP
Operating system:: Window 10 Pro
Outlook version: Outlook 2019
Email type or host: Email IMAP
Outlook version: Outlook 2019
Email type or host: Email IMAP
Good day
I got this code from Slipstick Systems "Pick a Folder to save a send message". What I want to achieve is that when send button is clicked a dialog box on needs to open and the user will select between CommercialClients & PersonalClient then scroll to that client and save the message under sub dir Email Send
I am struggling to get this to work
When I run Debug to cursors the below dialog popup. When I run Debug to cursor the 2 dialog popup. I need the 1st dialog to popup. And there need be a nothing return if the user do not want to save the email.
I got this code from Slipstick Systems "Pick a Folder to save a send message". What I want to achieve is that when send button is clicked a dialog box on needs to open and the user will select between CommercialClients & PersonalClient then scroll to that client and save the message under sub dir Email Send
I am struggling to get this to work
Code:
Public Sub SaveMessageAsMsg()
Dim oMail As Outlook.MailItem
Dim objItem 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
StrUserPath = "\\JK_Server-PC\Users\JK_Server\My Documents\JKBrokers\Clients\"
StrFolderpath = BrowseForFolder(StrUserPath)
For Each objItem In ActiveExplorer.Selection
If objItem.MessageClass = "IPM.Note" Then
Set oMail = objItem
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
Next
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
Invalid:
BrowseForFolder = False
End Function
When I run Debug to cursors the below dialog popup. When I run Debug to cursor the 2 dialog popup. I need the 1st dialog to popup. And there need be a nothing return if the user do not want to save the email.