我有一个宏,我在vba中写道,以获取电子邮件中的选定文本,现在在MsgBox中显示它 .
当我在电子邮件中运行带有所选文本的宏并且在其自己的窗口中打开电子邮件消息时,这非常有用 .
当我尝试使用在主Outlook程序的电子邮件窗格中选择的文本时,它给出了一个错误“对象变量或没有设置块变量”这来自“Set insp”行
有任何想法吗?
Sub showseltext()
Dim msg As Outlook.MailItem
Dim insp As Outlook.Inspector
Set insp = Application.ActiveInspector
If insp.CurrentItem.Class = olMail Then
Set msg = insp.CurrentItem
If insp.EditorType = olEditorWord Then
Set hed = msg.GetInspector.WordEditor
Set appWord = hed.Application
Set rng = appWord.Selection
MsgBox (rng)
End If
End If
Set appWord = Nothing
Set insp = Nothing
Set rng = Nothing
Set hed = Nothing
Set msg = Nothing
End Sub
1 回答
你需要检查检查员是否什么都没有,如果是,那么oyu需要利用资源管理器对象 . 以下是您编写的代码以包含该检查