JohanKotze
Senior Member
- OS Version(s)
- Windows
- Outlook version
- Outlook 2019 64-bit
- Email Account
- IMAP
Operating system:: Windows 10 Pro
Outlook version: 2019
Email type or host: IMAP
Outlook version: 2019
Email type or host: IMAP
Hi I am new to Outlook VBA and follow Slipstick for awhile now are interested in Saving Send Email to a Folder using "Pick the Folder Location", I get a "compile error sub section not define" at ReplaceCharsForFileName. Here the code from Slipstick that I put in ThisOutlookSession
I hope Idid the BrowseForFolder Function right.
--------------------------
Option Explicit
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 enviro As String
Dim strFolderpath As String
enviro = CStr(Environ("USERPROFILE"))
'Defaults to Documents folder
' get the function at How to use Windows File Paths in a Macro
strFolderpath = enviro & "\\JK_Server-PC\Users\JK_Server\My Documents\JKBrokers\Clients\" 'BrowseForFolder
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
‐-----------------------------
I did add the ReplaceCharsForFilename to ThisOutlookSession
------------------------------
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
-------‐--------------------
but I get an error message that say "Marco Failed"
I hope Idid the BrowseForFolder Function right.
--------------------------
Option Explicit
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 enviro As String
Dim strFolderpath As String
enviro = CStr(Environ("USERPROFILE"))
'Defaults to Documents folder
' get the function at How to use Windows File Paths in a Macro
strFolderpath = enviro & "\\JK_Server-PC\Users\JK_Server\My Documents\JKBrokers\Clients\" 'BrowseForFolder
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
‐-----------------------------
I did add the ReplaceCharsForFilename to ThisOutlookSession
------------------------------
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
-------‐--------------------
but I get an error message that say "Marco Failed"