2016-02-26 184 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