2009-09-15 70 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