2016-02-26 269 views
2

我正在使用一些代码在电子邮件中插入最后一个剪贴板打印屏幕,但有没有办法选择最后3个打印屏幕?或者选择多个打印屏幕插入电子邮件?谢谢。剪贴板粘贴到电子邮件

Sub clipboardcopy() 
    Dim OutApp As Object 
    Dim OutMail As Object 
    Dim olInsp As Object 
    Dim oRng As Object 


    On Error Resume Next 
    Set OutApp = GetObject(, "Outlook.Application") 
    If Err <> 0 Then Set OutApp = CreateObject("Outlook.Application") 

    On Error GoTo 0 
    Set OutMail = OutApp.CreateItem(0) 
    With OutMail 
     .To = "" 
     .CC = "" 
     .BCC = "" 
     .Subject = "PRINT SCREEN" 

     Set olInsp = .GetInspector 
     Set wdDoc = olInsp.WordEditor 
     Set oRng = wdDoc.Range 
     oRng.collapse 1 
     oRng.Paste 
     .Display 
    End With 

    Set OutMail = Nothing 
    Set OutApp = Nothing 
    Set olInsp = Nothing 
    Set wdDoc = Nothing 
    Set oRng = Nothing 
End Sub 

回答

1

对不起,我不认为这是可能的。

标准Windows剪贴板一次仅包含1个项目。

Office clipboard包含多个项目,但无法通过VBA访问。

+0

然后当我按下打印屏幕时有什么方法可以插入吗? – wittman

+0

VBA无法侦听事件的剪贴板。这限制了你的选择。您可以编写定期检查剪贴板更改的代码。但是,因为VBA在一个线程上运行,您可能会发现这会降低其他一切。也很难避免阻止你想运行的任何其他代码。 –

0

如果您想要多个打印屏幕,请将其附加到当前邮件而不是创建新邮件。

这个想法看起来像这样。

On Error resume next 
Set currItem = ActiveInspector.currentitem 
on error goto 0 

if curritem is nothing then 

    Set OutMail = CreateItem(0) 
    With OutMail 
     .To = "" 
     .CC = "" 
     .BCC = "" 
     .Subject = "PRINT SCREEN" 
     .Set olInsp = .GetInspector 
     .Set wdDoc = olInsp.WordEditor 
     .Set oRng = wdDoc.Range 
     oRng.collapse 1 
     oRng.Paste 
     .Display 
    End With 

Else 
    If curritem.class = olmail 
     if curritem.subject = "PRINT SCREEN" then 
      Set outMail = curritem 

      ' code to append print screen to body of curritem 

     End If 
    End If 
End If 
+0

嗨,谢谢你的回答,但它不起作用。我到现在为止只有剪贴板中的一个粘贴,但我仍然会寻找多个粘贴。 – wittman