2009-09-15 71 views
6

編程,當然。影像保存在Outlook 2007

已經在超級用戶上詢問this question,我正在着手編寫一個簡單的宏,以便在Outlook 2007中的HTML郵件(電子郵件或提要)中顯示圖像,並允許將其保存到磁盤。

不幸的是,我還沒有能夠找到其中的OL對象模型我可以引用鏈接的圖像,或HTML內容本身。查找附件很容易,它的鏈接/顯示圖像是我的問題。

任何幫助?當然,如果你有更好的非程序化的回答,我會很高興地看到, - 上的超級用戶了,當然...

回答

2

這是基於MSDN文檔。我沒有Outlook來測試它。

假設你有打開電子郵件,您可以呼籲MailItem實例GetInspector方法,你必須&使用其HTMLEditor property得到處理的DOM。

從現在起,你可以撥打常規方法,如document.Images得到處理的所有圖像元素。我不知道,如何將它本地保存到磁盤上,但我相信,必須有一些方法才能做到這一點。

1

我有第二個看看shahkalpeshs回答,並用以下解決方案上來: (寫在Outlook 2003)

Option Explicit 

Private Sub getImages() 
    Dim xmlhttp_ As xmlhttp 
    Dim htmldoc As Object 
    Dim currentImage As Object 
    Dim currentResponse() As Byte 

    Dim startTime As Date 
    Dim maxTime As Long 

    Dim pathFolder As String 
    Dim pathFull As String 
    Dim nrFile As Integer 

    pathFolder = "C:\YourFolder\Images\" '"(small fix for stackoverflow syntaxhighlighter) 
    maxTime = 30 ' max time to load 1 File in seconds ' 

    If Me.ActiveWindow.CurrentItem.GetInspector.EditorType = olEditorHTML Then 
     Set htmldoc = Me.ActiveWindow.CurrentItem.GetInspector.HTMLEditor 
     Set xmlhttp_ = New xmlhttp 

     For Each currentImage In htmldoc.images 

      xmlhttp_.Open "GET", currentImage.src 
      If Left(currentImage.src, 8) <> "BLOCKED:" Then 
       xmlhttp_.Send 
       startTime = Now 

       pathFull = pathFolder & currentImage.nameProp 
       pathFull = Replace(pathFull, "?", vbNullString) 
       pathFull = Replace(pathFull, "&", vbNullString) 

       Do While xmlhttp_.readyState <> 4 
        If DateTime.DateDiff("s", startTime, Now) > maxTime Then Exit Do 
        DoEvents 
       Loop 

       If xmlhttp_.readyState = 4 Then 
        If Dir(pathFull) <> "" Then Kill pathFull 
        nrFile = freeFile 

        Open pathFull For Binary As #nrFile 
        currentResponse = xmlhttp_.responseBody 
        Put #nrFile, , currentResponse 
        Close #nrFile 
       End If 
      End If 
     Next currentImage 
    End If 

    Set xmlhttp_ = Nothing 
    Set currentImage = Nothing 
    Set htmldoc = Nothing 
End Sub 

該代碼會下載所有那些ActiveWindow顯示圖像和將其保存在一個文件夾中。

您需要添加一個引用微軟XML(任何版本> = 2.6應工作),通過工具 - >在VBA編輯器

引用如果你願意,你也可以設置一個參考Microsoft HTML對象庫和變化:

Dim htmldoc As Object 
    Dim currentImage As Object 

到:

Dim htmldoc As HTMLDocument 
    Dim currentImage As HTMLImg 

關於你的評論:

@marg,感謝您的詳細答覆。我仍然無法相信該解決方案具有如此令人費解 - 圖像已被顯示,我爲什麼要再次下載呢?如果我只想保存一張圖像呢? (在Outlook 2003中,你可以右鍵點擊圖片,選擇另存爲...現在沒了。)由於這是關閉一個實際可行的解決方案,並且因爲似乎沒有在當前的Outlook任何更好的解決方案 - 我給你的賞金...

我沒有2007尋找一個非編程解決方案。

我不相信MailItem對象(CurrentItem在我的解決方案是一個MailItem)存在很大的分歧版本之間(但我立足於0%的研究是假設:d),我沒能找到直接的本地路徑即使我很確定他們應該在你的瀏覽器緩存文件夾中,所顯示的圖像存儲在那裏。搜索名爲currentImage.nameProp的文件並將其複製到目標文件夾將是替代解決方案。簡單地重新下載圖像應該不是那麼糟糕:D

+0

+1。很好的答案! – 2010-06-27 17:45:30

+0

感謝您的詳細回覆。我仍然無法相信該解決方案具有如此令人費解 - 圖像已被顯示,我爲什麼要再次下載呢?如果我只想保存一張圖像呢? (在Outlook 2003中,您可以右鍵單擊該圖像,然後選擇另存爲...)因爲這是關閉到一個實際可行的解決方案,並且因爲目前的Outlook似乎沒有更好的解決方案 - 我給你的賞金... – AviD 2010-06-29 23:27:10

+0

看到我編輯的答案。 – marg 2010-06-30 17:50:05