Outlook Download Files from Hyperlink

六眼飞鱼酱① 提交于 2019-12-22 01:18:41

问题


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?


回答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


来源:https://stackoverflow.com/questions/31517099/outlook-download-files-from-hyperlink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!