How to get Selected Body message Text

  • Thread starter pasteface method crashing outlook
  • Start date
Status
Not open for further replies.
P

pasteface method crashing outlook

Hi,

I need to handle an event whenever we select something in mail body. Can

anyone say how to handle this event and how to get selected text.

I'm developing an outlook add-in in ATL COM(VC++)

Regards

Kiran. S
 
There is no such event in the Outlook object model. If you are using

WordMail you can get Inspector.WordEditor as a Word.Document object and use

the Word Object model for that. If you are using HTML then you would have to

use the IHTMLDocument object model.

"pasteface method crashing outlook"

<pastefacemethodcrashingoutlook> wrote in message

news:BAF45B97-8706-4AED-AE9B-9AE409C037F0@microsoft.com...
> Hi,

> I need to handle an event whenever we select something in mail body. Can
> anyone say how to handle this event and how to get selected text.

> I'm developing an outlook add-in in ATL COM(VC++)

> Regards
> Kiran. S
 
Thanks Ken,

I tried Word Object Model and tried to capture the WordEditor of an mail

item. But inspector->get_WordEditor() is giving null pointer.

Code:

CComQIPtr<Outlook::_Inspector> spInspector;

CComPtr<MSWord::_Document> spWordDoc;

CComPtr<MSWord::Selection> spWordSelection;

CComPtr<MSWord::_Application> spWordApp;

spMailItem->get_GetInspector(&spInspector);

CComPtr<Outlook::_Application> spApp;

spInspector->get_EditorType(&editType);

BSTR str;

VARIANT_BOOL vTemp;

spInspector->IsWordMail(&vTemp);

if(vTemp == VARIANT_TRUE)

{

spInspector->get_WordEditor((IDispatch**)&spWordDoc);

spWordDoc->get_Application(&spWordApp);

spWordApp->get_Selection(&spWordSelection);

spWordSelection->get_Text(&str);

}

Please let me know if any issue found.

Regards

Kiran. S
wrote:


> There is no such event in the Outlook object model. If you are using
> WordMail you can get Inspector.WordEditor as a Word.Document object and use
> the Word Object model for that. If you are using HTML then you would have to
> use the IHTMLDocument object model.

> >

>

> "pasteface method crashing outlook"
> <pastefacemethodcrashingoutlook> wrote in message
> news:BAF45B97-8706-4AED-AE9B-9AE409C037F0@microsoft.com...
> > Hi,
> > I need to handle an event whenever we select something in mail body. Can
> > anyone say how to handle this event and how to get selected text.
> > I'm developing an outlook add-in in ATL COM(VC++)
> > Regards
> > Kiran. S


>
 
Where are you calling that code?

I've seen, especially in Outlook 2007, that WordEditor is null up until the

first Inspector.Activate() event. For example it's null in

Inspectors.NewInspector() because you're only getting a weak object

reference at that point.

If there is no Inspector then obviously there can't be a WordEditor object

since there is no Inspector.

"pasteface method crashing outlook"

<pastefacemethodcrashingoutlook> wrote in message

news:176F9A27-950A-4E6B-988E-ECE67B4CDB1B@microsoft.com...
> Thanks Ken,

> I tried Word Object Model and tried to capture the WordEditor of an mail
> item. But inspector->get_WordEditor() is giving null pointer.
> Code:
> CComQIPtr<Outlook::_Inspector> spInspector;

> CComPtr<MSWord::_Document> spWordDoc;
> CComPtr<MSWord::Selection> spWordSelection;
> CComPtr<MSWord::_Application> spWordApp;

> spMailItem->get_GetInspector(&spInspector);
> CComPtr<Outlook::_Application> spApp;
> spInspector->get_EditorType(&editType);
> BSTR str;
> VARIANT_BOOL vTemp;

> spInspector->IsWordMail(&vTemp);

> if(vTemp == VARIANT_TRUE)
> {

> spInspector->get_WordEditor((IDispatch**)&spWordDoc);

> spWordDoc->get_Application(&spWordApp);
> spWordApp->get_Selection(&spWordSelection);
> spWordSelection->get_Text(&str);
> }

> Please let me know if any issue found.

> Regards
> Kiran. S
 
I'm call the code when we change mail item in main pane( BY handling

Command-Bar events). I'm able to get Inspector pointer but its WordEditor is

returning NULL. Using the below code to capture Inspector pointer.

Code:

CComPtr< Outlook::Selection>spSelection;

m_pExplorer->get_Selection(&spSelection);

BSTR strname;

if(spSelection)

{

CComPtr< IDispatch > spItem;

CComVariant vCount(1);

spSelection->Item(vCount,&spItem);

if(!spItem)

return;

ATLASSERT(spItem);

CComQIPtr< Outlook::_MailItem> spMailItem(spItem);

ATLASSERT(spMailItem);

fprintf(fileptr,"[WSforOutlookMailItemSearching]->spMailItem::Success\r\n");

fflush(fileptr);

CComQIPtr<Outlook::_Inspector> spInspector;

spMailItem->get_GetInspector(&spInspector)

}

- Kiran. S
wrote:


> Where are you calling that code?

> I've seen, especially in Outlook 2007, that WordEditor is null up until the
> first Inspector.Activate() event. For example it's null in
> Inspectors.NewInspector() because you're only getting a weak object
> reference at that point.

> If there is no Inspector then obviously there can't be a WordEditor object
> since there is no Inspector.

> >

>

> "pasteface method crashing outlook"
> <pastefacemethodcrashingoutlook> wrote in message
> news:176F9A27-950A-4E6B-988E-ECE67B4CDB1B@microsoft.com...
> > Thanks Ken,
> > I tried Word Object Model and tried to capture the WordEditor of an mail
> > item. But inspector->get_WordEditor() is giving null pointer.
> > Code:
> > CComQIPtr<Outlook::_Inspector> spInspector;
> > CComPtr<MSWord::_Document> spWordDoc;
> > CComPtr<MSWord::Selection> spWordSelection;
> > CComPtr<MSWord::_Application> spWordApp;
> > spMailItem->get_GetInspector(&spInspector);
> > CComPtr<Outlook::_Application> spApp;
> > spInspector->get_EditorType(&editType);
> > BSTR str;
> > VARIANT_BOOL vTemp;
> > spInspector->IsWordMail(&vTemp);
> > if(vTemp == VARIANT_TRUE)
> > {
> > spInspector->get_WordEditor((IDispatch**)&spWordDoc);
> > spWordDoc->get_Application(&spWordApp);
> > spWordApp->get_Selection(&spWordSelection);
> > spWordSelection->get_Text(&str);
> > }
> > Please let me know if any issue found.
> > Regards
> > Kiran. S


>
 
You would need to display the Inspector.

"pasteface method crashing outlook"

<pastefacemethodcrashingoutlook> wrote in message

news:8990F45A-4C5F-493E-8826-2CA7078A281E@microsoft.com...

> I'm call the code when we change mail item in main pane( BY handling
> Command-Bar events). I'm able to get Inspector pointer but its WordEditor
> is
> returning NULL. Using the below code to capture Inspector pointer.

> Code:
> CComPtr< Outlook::Selection>spSelection;
> m_pExplorer->get_Selection(&spSelection);

> BSTR strname;
> if(spSelection)
> {

> CComPtr< IDispatch > spItem;
> CComVariant vCount(1);
> spSelection->Item(vCount,&spItem);
> if(!spItem)
> return;
> ATLASSERT(spItem);
> CComQIPtr< Outlook::_MailItem> spMailItem(spItem);
> ATLASSERT(spMailItem);

> fprintf(fileptr,"[WSforOutlookMailItemSearching]->spMailItem::Success\r\n");
> fflush(fileptr);

> CComQIPtr<Outlook::_Inspector> spInspector;
> spMailItem->get_GetInspector(&spInspector)
> }

> - Kiran. S
 
can you tell me which event is needed to handle , when we select the text in

outlook 2007.

-Kiran.S
wrote:


> You would need to display the Inspector.

> >

>

> "pasteface method crashing outlook"
> <pastefacemethodcrashingoutlook> wrote in message
> news:8990F45A-4C5F-493E-8826-2CA7078A281E@microsoft.com...
> > I'm call the code when we change mail item in main pane( BY handling
> > Command-Bar events). I'm able to get Inspector pointer but its WordEditor
> > is
> > returning NULL. Using the below code to capture Inspector pointer.
> > Code:
> > CComPtr< Outlook::Selection>spSelection;
> > m_pExplorer->get_Selection(&spSelection);
> > BSTR strname;
> > if(spSelection)
> > {
> > CComPtr< IDispatch > spItem;
> > CComVariant vCount(1);
> > spSelection->Item(vCount,&spItem);
> > if(!spItem)
> > return;
> > ATLASSERT(spItem);
> > CComQIPtr< Outlook::_MailItem> spMailItem(spItem);
> > ATLASSERT(spMailItem);
> > fprintf(fileptr,"[WSforOutlookMailItemSearching]->spMailItem::Success\r\n");
> > fflush(fileptr);
> > CComQIPtr<Outlook::_Inspector> spInspector;
> > spMailItem->get_GetInspector(&spInspector)
> > }
> > - Kiran. S


>
 
There is no event for that in the Outlook object model.

You'd have to open the item so it was being handled by WordMail, get

Inspector.WordEditor as a Word.Document object, then get the Parent property

of that as Word.Application and use the

Word.Application.WindowSelectionChange() event.

If the text was selected in the reading pane I don't know of a way to get an

event for that at all.

"pasteface method crashing outlook"

<pastefacemethodcrashingoutlook> wrote in message

news:774C1A99-AEC8-4E82-BFB9-D150A67D2647@microsoft.com...
> can you tell me which event is needed to handle , when we select the text
> in
> outlook 2007.

> -Kiran.S
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
R Reply with custom form & selected data from message body Outlook VBA and Custom Forms 3
D Delete selected text in outgoing email body Outlook VBA and Custom Forms 0
H Move Selected emails to Local Drive Outlook VBA and Custom Forms 0
D Outlook VBA forward the selected email to the original sender’s email ID (including the email used in TO, CC Field) from the email chain Outlook VBA and Custom Forms 2
E Outlook 365 Save Selected Email Message as .msg File - oMail.Delete not working when SEARCH Outlook VBA and Custom Forms 0
E Save Selected Email Message as .msg File - digitally sign email doesn't works Outlook VBA and Custom Forms 1
Witzker Add a text line at the end of the note field in all selected Contacts Outlook VBA and Custom Forms 7
O Replace hard returns with soft returns on selected text and button to QAT Using Outlook 5
N Save Selected Email Message as .msg File Outlook VBA and Custom Forms 12
G VBA to save selected Outlook msg with new name in selected network Windows folder Outlook VBA and Custom Forms 1
N Save selected messages VBA does not save replies and/or messages that contain : in subject Outlook VBA and Custom Forms 1
Bering Forward selected email without the original email appended Outlook VBA and Custom Forms 0
A Apply Selected Emails to outlook rules and Run Rules Using Outlook 5
B Change row background color of selected item Using Outlook 1
T Change the selected Message in the Outlook window Outlook VBA and Custom Forms 2
H Custom Signature Not Displayed When Account Selected Outlook VBA and Custom Forms 10
J Checkboxes when selected will appear in a textbox in Outlook 2016 Outlook VBA and Custom Forms 1
K How to reference the selected folder Outlook VBA and Custom Forms 1
R VBA Code to permanently delete selected email Outlook VBA and Custom Forms 10
P Outlook 2013 opens with FILE tab selected. Using Outlook 3
C Change Subject Line in Selected Emails Outlook VBA and Custom Forms 1
G Autocomplete adds suspicious "@unknown.email" to selected contacts Using Outlook 1
D Saving Selected Emails as PDF and saving Attachments Outlook VBA and Custom Forms 6
D Print Attachments only in selected emails using a macro Outlook VBA and Custom Forms 3
O On click,I want to change subject line of selected mail and then reply to particular email and move Using Outlook 3
B Macro to manually move selected emails to network folder Outlook VBA and Custom Forms 1
M code to move selected Outlook contacts to another folder Using Outlook 3
A Helping OL remember which calendars were selected Using Outlook 6
Diane Poremsky Save Selected Email Message as .msg File Using Outlook 11
D Delete selected text from incoming emails Outlook VBA and Custom Forms 25
mikolajek Random message selected after hard delete Using Outlook 4
Diane Poremsky Working with All Items in a Folder or Selected Items Using Outlook 0
Diane Poremsky Outlook VBA: Work with Open Item or Selected Item Using Outlook 0
A VBA to create meeting from template from a time slot selected in someone's calendar Outlook VBA and Custom Forms 5
Diane Poremsky Create Task or Appointment and Insert Selected Text Using Outlook 0
Yusufbodrum Highlighting selected mails in any folder Using Outlook 2
P Subject change on selected emails Outlook VBA and Custom Forms 14
C Autofill subject line in appointment from options selected in combobox Using Outlook 6
P Is it possible to write a macro to email to all addresses of selected contacts? Using Outlook 1
M Save selected email message as .msg file (with user to choose folder location) Outlook VBA and Custom Forms 14
S Macro to print & move selected emails? Using Outlook 3
L Selected Contacts For E-Mails Using Outlook 19
K Help! I selected every contact and mistakenly made them all the same category Using Outlook 1
C Outlook 2010 Address Book, won't stay selected Using Outlook 5
L Outlook 2007 E-Mail From Selected Task Using Outlook 18
L Email For Selected Contacts Using Outlook 5
D Trigger macro to run when selected email is opened Using Outlook 3
D Launch Outlook showing only selected messages. Using Outlook 1
J Capturing forward event when multiple items are selected Using Outlook 0
S Printing Selected Date Range in Monthly Style Using Outlook 1

Similar threads

Back
Top