0

I'm looking for some assistance with automating a task I do several times per day.

I receive emails from a certain address which I automatically sort (using Rules) into a dedicated folder.

These emails contain hyperlinks to documents to download from the web; however the links are not written as a URL, rather there is a link saying "Download all Documents".

I click on this link, it opens the URL which is a zip file of all the documents. I then save this zip file in a certain naming format into a certain folder.

I'm looking to automate this process. It's a fiddly task doing it manually because I receive many such emails, and renaming them takes time because the default name contains illegal characters.

I've done some programming before, but only a little bit in VBA (Excel) and never for Outlook.

I've searched through the forums for similar questions, and it appears I can use the URLDownloadToFile function (e.g. UrlDownloadToFile in Access 2010 - Sub or Function not Defined); however I need to pass a URL to that function, and I don't know how to get that out of the email since it's not contained within the body of the email.

Can anyone help me here?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Oliver
  • 1
  • 1
  • 2
  • would you be able to post the full working code as an answer and accept it? It would help people like me and others too :) – anky Dec 23 '19 at 17:00

1 Answers1

1

The URL is in the hyperlink. https://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.hyperlink_members.aspx

Sub HyperlinkAddress()

Dim msg As Object
Dim oDoc As Object
Dim h As Object

Set msg = ActiveInspector.currentItem

If msg.GetInspector.EditorType = olEditorWord Then

    Set oDoc = msg.GetInspector.WordEditor

    For Each h In oDoc.Hyperlinks
        Debug.Print "Displayed text: " & h.TextToDisplay & vbCr & " - Address: " & h.Address
        'h.Follow
    Next

End If

Set msg = Nothing
Set oDoc = Nothing
Set h = Nothing

End Sub
niton
  • 8,771
  • 21
  • 32
  • 52
  • Thanks. I've actually managed to do it in a different way - by using the .HTMLBody property, then finding the "Download All Documents" string within that, then finding the link address in the html code beside that link. That's a bit clumsy though, your way seems cleaner. Only thing is I can't use it by just selecting the email in outlook, I have to open it in a window. Is there a way around this? I can write code to open the selection in a window, and then close it at the end, but again, that feels a bit clumsy. – Oliver Jul 22 '15 at 08:11
  • Set msg = ActiveExplorer.Selection.Item(1) – niton Jul 22 '15 at 16:48
  • Great, thanks! Have written all my code, tested it and it's working well. – Oliver Jul 23 '15 at 08:10