Outlook 2003のテキストを選択し取得するためにマクロVBA
-
25-09-2019 - |
質問
私は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これまでの問題を解決するために、任意の参照を追加する必要がありますか?
解決
@Kusleikaは、私はあなたが提案したオプションを試してみましたが、まだ同じエラーが思い付きました。 助けてくれてありがとう。
私は適切な方法で私の質問を言葉で表現していなかったかもしれませ
いくつかのより多くのプレビューペインで、メールの選択したテキストを取得するためにその可能性はないことを明らかにしたグーグル。 http://www.eggheadcafe.com/forumarchives/outlookprogram_VisualBasica/Aug2005/post23481044。 ASP の
だから、私はメールアイテムウィンドウからアクションを行うことができるように要件を調整する必要がありました。
次のコードは、私を助けた(私のニーズに合うようにいくつかの変更をしなければならなかった)。
Sub Blue_Code_Highlight()
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 = olEditorHTML Then
Set hed = msg.GetInspector.HTMLEditor
Set rng = hed.Selection.createRange
rng.pasteHTML "<font style='color: blue; font-family:Times New Roman; font-size: 10pt;'>" & rng.Text & "</font><br/>"
End If
End If
Set insp = Nothing
Set rng = Nothing
Set hed = Nothing
Set msg = Nothing
End Sub
ソース: http://www.outlookcode.com/threads.aspx ?forumid = 4&イベントID = 26992 の
助けを@Kusleikaのおかげで、私はこのスレッドを閉じることができます。 Plsは私に知らせます。
他のヒント
の場合には、誰かが代わりにHTMLのワードエディタを使用しているだけで、あなたもこの部分を挿入することができます:
If insp.EditorType = olEditorWord Then
Set hed = msg.GetInspector.WordEditor
Set word = hed.Application
Set rng = word.Selection
rng.Font.Name = "Times New Roman"
rng.Font.Size = 10
rng.Font.Color = wdColorBlack
End If
単語が編集者である場合にも、同様の取得します。私は受け入れ答えにコメントにこれを貼り付けしようとしたが、それは答えとして投稿して、書式設定破壊され、かなり無用だった。
Dim oText As Range
TextRangeのはTextFrameオブジェクトのプロパティです。これは、Rangeオブジェクトを返します。何TextRangeのオブジェクトがありません。