Macro VBA para obter o texto selecionado no Outlook 2003
-
25-09-2019 - |
Pergunta
Estou tentando usar o trecho de código para obter o texto selecionado no 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 executar esta macro recebo a mensagem de erro
---------------------------
Microsoft Visual Basic
---------------------------
Compile error:
User-defined type not defined
Eu preciso de adicionar quaisquer referências para corrigir isso?
Solução
@Kusleika, eu tentei a opção que você tinha sugerido, e ainda os mesmos erros veio.Obrigado pela ajuda
Pode ser que eu não tinha expressado a minha pergunta de forma adequada
Mais algum googling revelou que não é possível obter o texto selecionado de um e-mail no painel de pré-visualização. http://www.eggheadcafe.com/forumarchives/outlookprogram_VisualBasica/Aug2005/post23481044.asp
Então eu tive que ajustar a exigência para que eu possa fazer uma ação a partir de um item de email janela.
O seguinte código me ajudou (tive que fazer algumas alterações para atender às minhas necessidades)
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 obrigado pela ajuda, posso fechar esta thread.Pls me avise.
Outras dicas
Caso alguém esteja usando o editor de palavras em vez do HTML, você também pode inserir esta 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
para se tornar semelhante quando a palavra é o editor. Tentei colar isso em um comentário sobre a resposta aceita, mas destruiu a formatação e foi bastante inútil, então postando como resposta.
Dim oText As Range
TexTrange é uma propriedade do objeto TextFrame. Ele retorna um objeto de intervalo. Não há objeto textrange.