Vba script including macro appears in rules but wont run

Status
Not open for further replies.

Paul Fone

New Member
Outlook version
Outlook 2010 64 bit
Email Account
POP3
Hi there

Here is a script for Outlook 2010 to click on the first hyperlink in an email. It shows up as a script in the rules in outlook - the macro appears in the developer tab in Macros and runs fine but it will not trigger live. Any help would be much appreciated

'Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub LaunchURL(Itm As Outlook.MailItem)
Set objOL = Application
Set objDoc = objOL.ActiveInspector.WordEditor
Set objSel = objDoc.Windows(1).Selection
objDoc.Hyperlinks(1).Follow
Set Itm = Nothing
Set objOL = Nothing
Set objDoc = Nothing
Set objSel = Nothing
End Sub
Sub LoopThruEmails()
Dim i As Long
Dim InboxItems As Outlook.Items
Dim thisEmail As Outlook.MailItem
Set InboxItems = GetItems(GetNS(GetOutlookApp), olFolderInbox)
' assume there are inbox items
For i = InboxItems.Count To 1 Step -1
If TypeName(InboxItems.Item(i)) = "MailItem" Then ' it's an email
Set thisEmail = InboxItems.Item(i)
thisEmail.Display
' Sleep (3000) ' wait 3 seconds
Dim currItem As Outlook.MailItem
Dim Insp As Outlook.Inspector
Set currItem = Application.ActiveInspector.CurrentItem
LaunchURL currItem
thisEmail.Close olDiscard
Exit Sub

End If
Next i
End Sub
Function GetOutlookApp() As Outlook.Application
' returns reference to native Application object
Set GetOutlookApp = Outlook.Application
End Function
Function GetNS(ByRef app As Outlook.Application) As Outlook.NameSpace
Set GetNS = app.GetNamespace("MAPI")
End Function
Function GetItems(olNS As Outlook.NameSpace, folder As OlDefaultFolders) As Outlook.Items
Set GetItems = olNS.GetDefaultFolder(folder).Items
End Function




Regards Paul Fone
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This line: Sub LaunchURL(Itm As Outlook.MailItem) tells it to only work when called by a rule or another script.
You need something like this to run it manually
Sub LaunchURL()
dim Itm As Outlook.MailItem
set itm = objOL.ActiveExplorer.Selection.Item(1)
 

Paul Fone

New Member
Outlook version
Outlook 2010 64 bit
Email Account
POP3
Hi Diane

I actually want it to run automatically using a rule but it doesn't work

Regards
Paul Fone
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
If run automatically by a rule, the rules passes a ref on the newly added item. Instead of using that one, you try to follow a link in the body of the current open email, see this line:
Code:
Set objDoc = objOL.ActiveInspector.WordEditor
 

Paul Fone

New Member
Outlook version
Outlook 2010 64 bit
Email Account
POP3
Hello Michael

I am a real novice at this so could you please explain where I place this line or what is my next step?
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
D.Moore VBA script fail after Office 365 update Using Outlook 8
S Change VBA script to send HTML email instead of text Outlook VBA and Custom Forms 3
dweller Outlook 2010 Rule Ignores VBA Script Outlook VBA and Custom Forms 2
N VBA Script to Open highlighted e-mail and Edit Message Outlook VBA and Custom Forms 5
K Outlook Archive to PST Files by Date Range VBA Script? Outlook VBA and Custom Forms 1
Peter H Williams Enable script containing VBA Outlook VBA and Custom Forms 12
R VBA Script Quick Parts Using Outlook 1
Q VBA Script to move item in secondary mailbox Outlook VBA and Custom Forms 2
N VBA Script to Send Automatic Emails from Outlook 2010 Outlook VBA and Custom Forms 1
O modify vba to run it as script rule Outlook VBA and Custom Forms 8
P How many subs can run in one outlook VBA script Using Outlook 5
J Email Parsing VBA Script for Outlook - NEEDED Outlook VBA and Custom Forms 7
R Adding vba to script list Outlook VBA and Custom Forms 4
F VBA script to highlight specific words Outlook VBA and Custom Forms 1
D VBA Script to extract text matching specific criteria Outlook VBA and Custom Forms 1
D VBA Script (Ask to where to save send mail) Outlook VBA and Custom Forms 1
M VBA script to allow mail merges of distribution groups? Using Outlook 7
D VBA script to auto download attachments and rename file according to subject line Outlook VBA and Custom Forms 23
Hudas Outlook VBA script reverting back to previous changes Outlook VBA and Custom Forms 2
J Outlook 2007 Rules & VBA: How to run a script on a report message (ReportItem) Using Outlook 14
V "Accept + Send the Response now", VBA script? Using Outlook 1
R Addins4Outlook TagIt! addin script or VBA module? Using Outlook 2
S Outlook VBA rule script to process both MailItem and MeetingItem Using Outlook 0
A VBA Script to Forward Spam to AntiSpam Provider Using "Blank" Form Outlook VBA and Custom Forms 2
L Limit VBA Script to one Outlook account Using Outlook 1
L Macro/VBA to Reply All, with the original attachments Outlook VBA and Custom Forms 2
L VBA unknown character Outlook VBA and Custom Forms 2
G Move tasks up/down todo list by VBA Outlook VBA and Custom Forms 1
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
K Use VBA to find Sender and Recipient from Microsfot 365 Journaled Email Items Outlook VBA and Custom Forms 3
J Want to learn VBA Macros for Outlook. What book can you recommend? Outlook VBA and Custom Forms 2
F VBA code to dock Styles whenever I write or edit an email Outlook VBA and Custom Forms 0
C VBA to prompt for Sent folder destination Outlook VBA and Custom Forms 3
B Adding signature to bottom of VBA reply email Outlook VBA and Custom Forms 1
B Change Font and Font size using VBA Outlook VBA and Custom Forms 9
M Outlook 2013 reminder email by using Outlook vba Outlook VBA and Custom Forms 2
R Limiting length of saved attachment in VBA Outlook VBA and Custom Forms 2
S Skype for business meeting vba code Outlook VBA and Custom Forms 1
C How to use VBA to show only items x days old or more Outlook VBA and Custom Forms 1
B VBA to convert email to task, insert text of email in task notes, and attach copy of original email Outlook VBA and Custom Forms 4
D Outlook VBA error extracting property data from GetRules collection Outlook VBA and Custom Forms 10
S Reference Custom Fields with VBA Outlook VBA and Custom Forms 2
PGSystemTester VBA To Change AppointmentItem.BusyStatus From MeetingItem Before Send Using Outlook 0
A VBA macro for 15 second loop in send and received just for 1 specific mailbox Outlook VBA and Custom Forms 1
O Email not leaving Outbox when using Excel VBA to sync Outlook account Outlook VBA and Custom Forms 4
G VBA Macro Calendar Printing Assistant 4
R Help Revising VBA macro to delete email over different time span Outlook VBA and Custom Forms 0
B VBA to Collapse Task Folder Groups Outlook VBA and Custom Forms 1
R Expand VBA Permanent Delete Code Outlook VBA and Custom Forms 6
shrydvd vba to secure zip attachments Outlook VBA and Custom Forms 3
Similar threads


















































Top