Outlook 2013 Run A Script

yuvaraj

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
Hi,

I tried to set a rules in outlook 2013 version, but unfortunately i found the run a script option in the action pane, but while clicking on the script underlined one can't able to find My Macro Name to proceed with the rules. Could you please suggest me what will be the issues in that?

Thanks,
Yuvaraj

Outlook Script Error.png
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
What script are you using? The name line needs to be formatted correctly - with the object in the (), not in a dim statement. (You also won't set the object in the macro - you don't use anything like set item = objApp.ActiveExplorer.Selection.Item(1) - the rule sets the item to the newly arrived item.

Public Sub scriptname (Item As Outlook.MailItem)


 

yuvaraj

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
Thanks for the reply Diane. Below is the script which am trying to execute, please find that and let me know any issues.

Option Explicit
Public Sub Application_NewMail()
Dim olapp As Object
Dim olmapi As Object
Dim olmail As Object
Dim olitem As Object
Dim objMyInbox As Object
Dim lrow As Integer
Dim olattach As Object
Dim str As String
Dim chckSubject As Integer
Dim valSubject As String
Dim olp As Object
Dim i As Integer

Const num As Integer = 6
Const path As String = "XXXXXXXXXX"
Const emailpath As String = "XXXXXXXXXXXX"
Const olFolderInbox As Integer = 6

Set olp = CreateObject("outlook.application")
Set olmapi = olp.GetNamespace("MAPI")
Set olmail = olmapi.GetDefaultFolder(num)
Set objMyInbox = olmapi.GetDefaultFolder(olFolderInbox)


If olmail.Items.Restrict("[UNREAD]=True").Count = 0 Then

MsgBox ("No Unread mails")

Else

For i = 1 To olmail.UnReadItemCount

For Each olitem In olmail.Items.Restrict("[UNREAD]=True")

valSubject = olitem.Subject

If valSubject Like ("*XXXXXXXXXX*") And olitem.Attachments.Count <> 0 Then

For Each olattach In olitem.Attachments

olattach.SaveAsFile path & Format(Date, "MM-dd-yyyy") & olattach.FileName

Next olattach

End If

olitem.UnRead = False
DoEvents
olitem.Save
Next olitem

Next i

End If

End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Sorry, I didn't get a chance to look at this. This Is not a run a script rule - it applies to new mail: Application_NewMail . What are you trying to do with it ? If you want to save attachments on certain messages as they arrive, see
 
Top