Home > OS >  Open specific URL from Outlook with Chrome
Open specific URL from Outlook with Chrome

Time:02-08

Our company use IE as the default browser, but certain application we are working with require chrome. since we can't abandon IE, we need to open specific \ certain links with chrome, only with outlook. I tried the following vba, which works great, but open automaticlly.

Sub LaunchURL(itm As MailItem)

Dim bodyString As String
Dim bodyStringSplitLine
Dim bodyStringSplitWord
Dim splitLine
Dim splitWord

bodyString = itm.Body
bodyStringSplitLine = Split(bodyString, vbCrLf)

For Each splitLine In bodyStringSplitLine
    bodyStringSplitWord = Split(splitLine, " ")

    For Each splitWord In bodyStringSplitWord
        If Left(splitWord, 7) = "http://" Then
            Shell ("C:\Program Files\Google\Chrome\Application\chrome.exe" & " " & splitWord)
        End If
    Next

Next

Set itm = Nothing

End Sub

Private Sub test()
    Dim currItem As MailItem
    Set currItem = ActiveInspector.CurrentItem
    LaunchURL currItem
End Sub

Is there any way to make this script work when the users clicks the url and not automaticlly ? or therefore any way to make this work when the users read the message (so he can unread and when read it will open when he needs to) ?

Sorry in advance for my bad english.

CodePudding user response:

Is there any way to make this script work when the users clicks the url and not automaticlly ?

Nope. There is no trivial way for getting this working per URL. The Outlook object mode doesn't provide anything for handling hyperlinks clicks. The best what you could do is to replace links with your owns and tracking this by navigating to your URLs and then forwarding to the original ones.

or therefore any way to make this work when the users read the message (so he can unread and when read it will open when he needs to) ?

You can handle the SelectionChange event of the Explorer class which is fired when the user selects a different or additional Microsoft Outlook item programmatically or by interacting with the user interface. This event also occurs when the user (either programmatically or via the user interface) clicks or switches to a different folder that contains items, because Outlook automatically selects the first item in that folder.

For inspector windows you may consider handling the Inspectors.NewInspector event which is fired whenever a new inspector window is opened, either as a result of user action or through program code.

CodePudding user response:

If the code runs automatically you probably have it in a rule.

To run code manually from a button when the item is open:

  • Change LaunchURL to standalone code.
    -Drop (itm As MailItem)
    -Add ActiveInspector.CurrentItem lines from Private Sub test()

or

  • Remove Private from Private Sub test()
  •  Tags:  
  • Related