J P
asked on
Outlook VBA, open selected mail item and click hyperlink contained within
I wish to open selected mail item in Outlook (using VBA within Outlook) and then click hyperlink labelled "Test".
ASKER
Line 4: has error "Run Time error '91': Object variable or with block variable not set"
then try
Sub macro()
' Set objOL = CreateObject("Outlook.Application")
Set NewMail = Application.ActiveExplorer.Selection.Item(1)
NewMail.display
res = NewMail.body
Set regex = CreateObject("VBScript.RegExp")
With regex
.Global = False
.MultiLine = False
.IgnoreCase = True
.Pattern = "HYPERLINK ""([^""]+?)""test"
End With
Set mtches = regex.Execute(res)
If mtches.Count > 0 Then
strHL = mtches(0).submatches(0)
Set oIE = CreateObject("InternetExplorer.Application")
oIE.navigate strHL, CLng(2048)
oIE.Visible = True
Do While oIE.Busy
DoEvents
Loop
End If
End Sub
ASKER
line 20: error "Run time error '462': the remote server machine does not exist or is unavailable"
the link is directed to what?
ASKER
The first code worked fine when the email was already open if that helps?
It did not work correctly when I was viewing it in the preview pane.
It did not work correctly when I was viewing it in the preview pane.
then try
Sub macro()
' Set objOL = CreateObject("Outlook.Application")
Set NewMail = Application.ActiveExplorer.Selection.Item(1)
NewMail.display
res = NewMail.body
Set regex = CreateObject("VBScript.RegExp")
With regex
.Global = False
.MultiLine = False
.IgnoreCase = True
.Pattern = "HYPERLINK ""([^""]+?)""test"
End With
Set mtches = regex.Execute(res)
If mtches.Count > 0 Then
strHL = mtches(0).submatches(0)
Set oIE = CreateObject("InternetExplorer.Application")
oIE.navigate strHL
oIE.Visible = True
Do While oIE.Busy
DoEvents
Loop
End If
End Sub
ASKER
Line 21: oIE.Visible = True
Get error "Run time error '-2147417848 (80010108)': Automation Error The object invoked has disconnected from its clients."
Get error "Run time error '-2147417848 (80010108)': Automation Error The object invoked has disconnected from its clients."
then try
Sub macro()
' Set objOL = CreateObject("Outlook.Application")
Set NewMail = Application.ActiveExplorer.Selection.Item(1)
NewMail.display
res = NewMail.body
Set regex = CreateObject("VBScript.RegExp")
With regex
.Global = False
.MultiLine = False
.IgnoreCase = True
.Pattern = "HYPERLINK ""([^""]+?)""test"
End With
Set mtches = regex.Execute(res)
If mtches.Count > 0 Then
strHL = mtches(0).submatches(0)
Set oIE = CreateObject("InternetExplorer.Application")
oIE.navigate strHL, CLng(2048)
Do While oIE.Busy
DoEvents
Loop
oIE.Visible = True
End If
End Sub
ASKER
Line 22: Do While oIE.busy
has the same error
"Run time error '-2147417848 (80010108)': Automation Error The object invoked has disconnected from its clients"
has the same error
"Run time error '-2147417848 (80010108)': Automation Error The object invoked has disconnected from its clients"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks it worked!
ASKER
Rgonzo1971 - following on from the correct code, how would I use GetElementByID for the loaded webpage ?
Pls open a new question
ASKER
Hi Rgonzo, I have open a new question: https://www.experts-exchange.com/questions/29093931/Interact-with-Webpage-from-Outlook.html
pls try
Open in new window
Regards