Private Sub Save_Click()
Dim myolapp As Outlook.Application
Dim myinspector As Outlook.Inspector
Dim newItem As Outlook.MailItem
Dim MaPI As NameSpace
Dim myNamespace As NameSpace
Dim myfolder As MAPIFolder
Dim FolderPath As String
Dim olobject As Inspector
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set olobject = Inspectors.Item(1)
Set objfrmmail = olobject.CurrentItem
Dim strpath, strDateReceived, strEmailSubject, strCustomerName, strJobNo, strBody, strTo, strCC As String
Dim strSentOn As String
strDateReceived = Replace(Replace(CStr(objfrmmail.ReceivedTime), "/", "-"), ":", "-")
strEmailSubject = objfrmmail.Subject
strEmailSubject = Replace(Replace(strEmailSubject, """", ""), "*", "")
strEmailSubject = Replace(Replace(strEmailSubject, "<", ""), ">", "")
strEmailSubject = Replace(Replace(strEmailSubject, "\", ""), "/", "")
strEmailSubject = Replace(Replace(strEmailSubject, ":", ""), "?", "")
strFrom = objfrmmail.SenderName
If strFrom = "" Then
Set MaPI = GetNamespace("MAPI")
strFrom = MaPI.CurrentUser
End If
strTo = objfrmmail.To
strCC = objfrmmail.CC
strBody = objfrmmail.Body
strBodyFormat = objfrmmail.BodyFormat
If strBodyFormat = 1 Then
strExt = ".txt"
Else
strExt = ".HTML"
End If
FolderPath = Path.Caption
'[COLOR=red]PHV Line of code
strpath = Left(FolderPath & strDateReceived & " " & strFrom & "; " & strEmailSubject, 251) & strExt
Old line of code
'strpath = FolderPath & strDateReceived & " " & strFrom & "; " & strEmailSubject & strExt [/color]
MsgBox (strpath)
msgstrpath = "\\ServerQG\Data\General E-Mail\" & strDateReceived & " " & strFrom & "; " & strEmailSubject & ".msg"
If objFSO.FileExists(strpath) = True Then
MsgBox "This email has already been saved in this folder", vbOKOnly
Else
On Error GoTo ErrTestFolder
Set testfolder = objFSO.GetFolder(FolderPath)
Set txtSO = testfolder.CreateTextFile("testfile.txt", True, False)
txtSO.WriteLine ("a new text file")
txtSO.Close
Set txtSO = Nothing
Set txtSO = objFSO.GetFile(FolderPath & "testfile.txt")
txtSO.Delete
Set txtSO = Nothing
Set testfolder = Nothing
Set objFSO = Nothing
On Error GoTo ErrHandler
If strBodyFormat = 1 Then
' MsgBox "plain"
' Set myolapp = CreateObject("Outlook.Application")
'Set myNamespace = myolapp.GetNamespace("MAPI")
'Set myfolder = myNamespace.GetDefaultFolder(olFolderInbox)
'Set newItem = myfolder.Items.Add(olMailItem)
'newItem.Subject = strEmailSubject
'newItem.To = strTo
'newItem.CC = strCC
'newItem.SentOnBehalfOfName = strFrom
'newItem.BodyFormat = olFormatHTML
'newItem.Body = strBody
'newItem.SaveAs strpath, olHTML
objfrmmail.SaveAs strpath, olPlain
Else
objfrmmail.SaveAs strpath, olHTML
End If
objfrmmail.SaveAs msgstrpath
End If
userfrmsaveemail.Hide
Set objfrmmail = Nothing
Set myinspector = Nothing
Set olobject = Nothing
Exit Sub
ErrTestFolder:
MsgBox "You do not have permission to use this folder. Please try again."
Exit Sub
Resume Next
ErrHandler:
MsgBox "An Error has occurred please contact Nitec with details of the email. Please click 'Yes' on the following security check "
Set myolapp = CreateObject("Outlook.Application")
Set myNamespace = myolapp.GetNamespace("MAPI")
Set myfolder = myNamespace.GetDefaultFolder(olFolderInbox)
Set newItem = myfolder.Items.Add(olMailItem)
newItem.Subject = strEmailSubject
newItem.To = "me@myaddress.com"
newItem.Body = msgstrpath & " " & strpath
'[COLOR=red] This is were the debug error points to
newItem.Send
[/color]
Resume Next
userfrmsaveemail.Hide
End Sub