使用电子邮件规则触发VBA脚本,是否可以将电子邮件正文发送到剪贴板?我发现了这个method,但它似乎无法发挥作用。
Sub SaveToClipboard(Item As Outlook.MailItem)
Dim Explorer As Outlook.Explorer
Dim oitem As Outlook.MailItem
Dim oData As MSForms.DataObject
Set Explorer = Application.ActiveExplorer
If Explorer.Selection.Count Then
Set CurrentItem = Explorer.Selection(1)
Set oitem = CurrentItem
oData = oitem.Body
oData.PutInClipboard
'Using this to test the output
MsgBox oData
End If
End Sub
接下来,我将如何搜索以" Info:"开头的电子邮件正文中的一行。并且只将该行复制到剪贴板?
答案 0 :(得分:0)
您缺少该网站上的示例中描述的重要内容。
同样使用传入的mailitem(itm as mailItem)。
Option Explicit
Private Sub SaveToClipboard_test()
Dim curritem As Object
Set curritem = ActiveExplorer.Selection(1)
If TypeOf curritem Is mailItem Then SaveToClipboard curritem
ExitRoutine:
Set curritem = Nothing
End Sub
Sub SaveToClipboard(itm As mailItem)
Dim oData As MSForms.DataObject
Dim strPaste As Variant
Set oData = New MSForms.DataObject
oData.SetText itm.body
oData.PutInClipboard
oData.GetFromClipboard
strPaste = oData.GetText
strPaste = Left(strPaste, 1024)
MsgBox strPaste
ExitRoutine:
Set oData = Nothing
End Sub