Peter H Williams
Member
- Outlook version
- Email Account
- POP3
It has been suggested that all my tasks be included in a VBA script rather than some items in the Outlook rule and others in the script.
I am now trying to do just that.
Put simply I take the Outlook.item (containing words in the Subject) and save the body to a file available for processing on an MT4 (Forex trading) platform.
So I create a file. create a list of any files to be processed and then wish to move the item and that's where I fail.
This code performs the required task but fails with the move.item (I have tried numerous alternatives but I believe this shows what I want to achieve.
I am now trying to do just that.
Put simply I take the Outlook.item (containing words in the Subject) and save the body to a file available for processing on an MT4 (Forex trading) platform.
So I create a file. create a list of any files to be processed and then wish to move the item and that's where I fail.
This code performs the required task but fails with the move.item (I have tried numerous alternatives but I believe this shows what I want to achieve.
Code:
Public fs, f1, f2
Public filepath_part1 As String, filepath_part2 As String, filepath_full As String, myfname As String
Public Sub ChangeSubjectForward(item As Outlook.MailItem)
Dim str1 As String
Dim myline
Dim myInbox As Outlook.Folder
Dim myDestFolder As Outlook.Folder
On Error GoTo Handler
str1 = item.Body
str2 = item.Subject
'If InStr(str1, "Reversal") > 0 And InStr(str2, "Reversals-Signal") > 0 Then
If InStr(str2, "Reversals-Signal") > 0 Then ' search the subject
getmyfile "ADS" ' gets the appropriate file path and name attached to f2
f2.writeline item.Body
f2.Close
writeListofFiles ' writes list of all files in the directory to a file to be accessed from MT4
' this is the code that has failed - I'd like to have a folder - say FolderA and sub folder FolderAsignals
'Set myDestFolder = Inbox.Folders("FolderA") ' changed for this example
'item.Move myDestFolder
End If
Exit Sub
Handler:
MsgBox "An unexpected Error has occurred." _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
'Resume MsgErr_Exit
End Sub