【发布时间】:2021-12-16 23:52:08
【问题描述】:
是否可以将您在邮件正文中选择的文本复制到变量中
例如
Sub cpytxt()
Set txt = Selection
'Do something
End Sub
【问题讨论】:
是否可以将您在邮件正文中选择的文本复制到变量中
例如
Sub cpytxt()
Set txt = Selection
'Do something
End Sub
【问题讨论】:
来源:gmayor,来源/字体:http://www.vbaexpress.com/forum/showthread.php?52985-VBA-get-selected-text-from-Outlook-email-body-and-use-in-Excel
Public Sub ShowTextSelected()
Dim OutApp As Object
Dim OutMail As Object
Dim olInsp As Object
Dim wdDoc As Object
Dim strText As String
On Error Resume Next
'Get Outlook if it's running
Set OutApp = GetObject(, "Outlook.Application")
'Outlook wasn't running, so cancel
If Err <> 0 Then
MsgBox "Outlook is not running so nothing can be selected!"
GoTo lbl_Exit
End If
On Error GoTo 0
Set OutMail = OutApp.ActiveExplorer.Selection.Item(1)
With OutMail
Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
strText = wdDoc.Application.Selection.Range.Text
End With
MsgBox strText
lbl_Exit:
Set OutMail = Nothing
Set OutApp = Nothing
Set olInsp = Nothing
Set wdDoc = Nothing
Exit Sub
End Sub
【讨论】: