Macro VBA per ottenere il testo selezionato in Outlook 2003
-
25-09-2019 - |
Domanda
Sto cercando di utilizzare questo frammento di codice per ottenere il testo selezionato 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
Quando si esegue questa macro ottengo l'errore
---------------------------
Microsoft Visual Basic
---------------------------
Compile error:
User-defined type not defined
Devo aggiungere eventuali riferimenti a risolvere questo?
Soluzione
@Kusleika, ho provato l'opzione che aveva suggerito ed ancora gli stessi errori si avvicinò. Grazie per l'aiuto
Può essere che non avevo formulato la mia domanda in modo corretto
Alcuni più googling ha rivelato che la sua non è possibile ottenere il testo selezionato di una posta nel quadro di anteprima. http://www.eggheadcafe.com/forumarchives/outlookprogram_VisualBasica/Aug2005/post23481044. asp
Così ho dovuto regolare il requisito in modo che io possa fare un'azione da una finestra di elemento di posta.
Il seguente codice mi ha aiutato (ha dovuto apportare alcune modifiche per soddisfare le mie esigenze)
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
Fonte: http://www.outlookcode.com/threads.aspx ? forumid = 4 & MessageId = 26992
@Kusleika grazie per l'aiuto, posso chiudere questo thread. Pls fatemi sapere.
Altri suggerimenti
Nel caso in cui qualcuno sta usando l'editor di parola, invece di HTML, è possibile inserire anche questa parte:
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
per ottenere simili quando parola è l'editor. ho cercato di incollare questo in un commento sulla risposta accettata, ma è distrutto la formattazione ed ero abbastanza inutile, in modo da inviare messaggi come risposta.
Dim oText As Range
TextRange è una proprietà dell'oggetto TextFrame. Esso restituisce un oggetto Range. Non v'è alcun oggetto TextRange.