宏VBA获取Outlook 2003中选定的文本
我正在尝试使用此代码片段在 Outlook 2003 中获取所选文本。
Sub SelectedTextDispaly()
On Error Resume Next
Err.Clear
Dim oText As TextRange
''# Get an object reference to the selected text range.
Set oText = ActiveWindow.Selection.TextRange
''# Check to see whether error occurred when getting text object
''# reference.
If Err.Number <> 0 Then
MsgBox "Invalid Selection. Please highlight some text " _
& "or select a text frame and run the macro again.", _
vbExclamation
End
End If
''# Display the selected text in a message box.
If oText.Text = "" Then
MsgBox "No Text Selected.", vbInformation
Else
MsgBox oText.Text, vbInformation
End If
End Sub
运行此宏时,出现错误
---------------------------
Microsoft Visual Basic
---------------------------
Compile error:
User-defined type not defined
“我需要添加任何引用来修复此问题吗?”
I am trying to use this code snippet to get the selected text in outlook 2003
Sub SelectedTextDispaly()
On Error Resume Next
Err.Clear
Dim oText As TextRange
''# Get an object reference to the selected text range.
Set oText = ActiveWindow.Selection.TextRange
''# Check to see whether error occurred when getting text object
''# reference.
If Err.Number <> 0 Then
MsgBox "Invalid Selection. Please highlight some text " _
& "or select a text frame and run the macro again.", _
vbExclamation
End
End If
''# Display the selected text in a message box.
If oText.Text = "" Then
MsgBox "No Text Selected.", vbInformation
Else
MsgBox oText.Text, vbInformation
End If
End Sub
When running this macro I get the error
---------------------------
Microsoft Visual Basic
---------------------------
Compile error:
User-defined type not defined
Do I need to add any references to fix this up?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
@Kusleika,我尝试了您建议的选项,但仍然出现了相同的错误。
感谢您的帮助
可能是我没有以正确的方式表达我的问题
一些更多的谷歌搜索显示不可能在预览窗格中获取邮件的选定文本。 http://www.eggheadcafe.com/forumarchives/outlookprogram_VisualBasica/Aug2005/post23481044。 asp
所以我必须调整要求,以便我可以从邮件项目窗口执行操作。
以下代码帮助了我(必须进行一些更改以满足我的需要)
来源:http://www.outlookcode.com/threads.aspx?forumid=4&messageid=26992
@Kusleika 感谢您的帮助,我可以关闭此线程吗?请告诉我。
@Kusleika, I tried the option you had suggested and still the same errors came up.
Thanks for the help
May be I had not phrased my question in the proper way
Some more googling revealed that its not possible to get the selected text of a mail in preview pane. http://www.eggheadcafe.com/forumarchives/outlookprogram_VisualBasica/Aug2005/post23481044.asp
So I had to adjust the requirement so that I can do an action from an mail item window.
The following code helped me (had to make some changes to suit my needs)
Source:http://www.outlookcode.com/threads.aspx?forumid=4&messageid=26992
@Kusleika thanks for the help, can I close this thread. Pls let me know.
万一有人使用 word 编辑器而不是 html,您也可以插入此部分:
以在 word 是编辑器时获得类似的效果。我尝试将其粘贴到对已接受答案的评论中,但它破坏了格式并且非常无用,因此将其作为答案发布。
Just in case someone is using the word editor instead of html, you can also insert this part:
to get similar when word is the editor. i tried to paste this into a comment on the accepted answer, but it destroyed the formatting and was pretty useless, so posting as an answer.
TextRange 是 TextFrame 对象的一个属性。它返回一个 Range 对象。没有 TextRange 对象。
TextRange is a property of the TextFrame object. It returns a Range object. There is no TextRange object.