Macro VBA للحصول على نص محدد في Outlook 2003
-
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
هل أحتاج إلى إضافة أي مراجع لإصلاح هذا؟
المحلول
Kusleika ، جربت الخيار الذي اقترحته وما زلت نفس الأخطاء. شكرا للمساعدة
ربما لم أكن قد صاغت سؤالي بالطريقة الصحيحة
كشف بعض المزيد من googling أنه من غير الممكن الحصول على النص المحدد للبريد في جزء المعاينة. 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&messageid=26992
@Kusleika شكرًا للمساعدة ، هل يمكنني إغلاق هذا الموضوع. من فضلك دعني أعرف.
نصائح أخرى
فقط في حالة قيام شخص ما باستخدام محرر Word بدلاً من 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. يرجع كائن النطاق. لا يوجد كائن textrange.