Peter H Williams
Member
- Outlook version
- Email Account
- POP3
I have used vba with EXCEL extensively but want to write a small macro / script that operates from a RULE in Outlook. Simply check all incoming mail and if 'something' is in subject line then execute - i.e. extract data from body and write to a txt file for processing elsewhere.
I have ammended the Additional controls to include (i.e. a cross against it) anything starting with 'Microsoft Office Outlook'. I have changed the Trust Centre , macro security 'Check all macros - i.e. 3rd down in list. I have placed a 'breakpoint' against a first statement 'int1=1' in my code.
I now create a message with the appropriate header and send to myself, the message arrives but the script / macro breakpoint is not actioned and nothing appears to happen.
If I try and manually run the macro than I struggle
Tools, Macros - nothing in the main body and at the bottom of the screen
Macros in - Project1(VbaProject.OTM)
So I goto Tools , Visual Basic Editor
I can see the code but if I highlight the first line and DEBUG then I get the same blank list of Macros
Sound like something pretty basic. The code was for test purposes only.
I have ammended the Additional controls to include (i.e. a cross against it) anything starting with 'Microsoft Office Outlook'. I have changed the Trust Centre , macro security 'Check all macros - i.e. 3rd down in list. I have placed a 'breakpoint' against a first statement 'int1=1' in my code.
I now create a message with the appropriate header and send to myself, the message arrives but the script / macro breakpoint is not actioned and nothing appears to happen.
If I try and manually run the macro than I struggle
Tools, Macros - nothing in the main body and at the bottom of the screen
Macros in - Project1(VbaProject.OTM)
So I goto Tools , Visual Basic Editor
I can see the code but if I highlight the first line and DEBUG then I get the same blank list of Macros
Sound like something pretty basic. The code was for test purposes only.
Code:
Sub A1(MyMail As MailItem)
'=============================================creates email message
Dim int1 As Integer, int2 As Integer
Dim strID As String
Dim objMail As Outlook.MailItem
Dim str1 As String, str2 As String, str3 As String, str4 As String
Dim mailcontent As String
int1 = 1
str1 = "Hello"
strID = MyMail.EntryID
'Set objMail = Application.Session.GetItemFromID(strID)
'objMail.BodyFormat = olFormatPlain
'objMail.Save
mailcontent = objMail.Body
CreateMessage "my email address", "loads of interesting stuff" + vbCrLf + mailcontent, "My Subject Title"
Set objMail = Nothing
End Sub
Sub CreateMessage(mailaddress As String, mailcontent As String, mailsubject As String)
Set myOlApp = CreateObject("Outlook.Application")
Set myitem = myOlApp.CreateItem(olMailItem)
'Set myRecipient = myitem.Recipients.Add(mailaddress) // or
myitem.Recipients.Add (mailaddress)
myitem.Subject = mailsubject
myitem.Body = mailcontent
myitem.Display
myitem.Send
End Sub