PDA

View Full Version : Select some text from specified Outlook email to the Single Cell of the Excel Sheet



JOEYSCLEE
11-09-2016, 09:15 AM
Hi, there
Issue 1, is it possible to copy some text from selected Outlook email to "insert comment" of single Cell in Excel worksheet?

Issue 2, also want to know the Macro for those text from the selected Outlook email into single cell in Excel worksheet.

Actually, I have daily email which state style# & comment. Then, I need to insert the comment to the related style# in table of the Excel file.

Example
17553

gmayor
11-09-2016, 09:57 PM
The short answer is yes, but the method will depend on the format of the messages - see http://www.gmayor.com/extract_data_from_email.htm and also the link at the end of that page.

JOEYSCLEE
11-14-2016, 03:13 AM
Thanks for your reply! After reviewing your past post, found that you wrote VBA with the subject : VBA get selected text from Outlook email body and use in Excel before.

As per your post, the email body text can be selected. But, there was no code for transfer the selected text to Single Cell of Excel worksheet.

In my case, could you please help to advise how to transfer the selected text from Outlook email body to Excel worksheet with your previous advised code?

Sub test()
Dim OutApp As Object
Dim OutMail As Object
Dim olInsp As Object
Dim wdDoc As Object
Dim strText As String

On Error Resume Next
'Get Outlook if it's running
Set OutApp = GetObject(, "Outlook.Application")

'Outlook wasn't running, so cancel
If Err <> 0 Then
MsgBox "Outlook is not running so nothing can be selected!"
GoTo lbl_Exit
End If
On Error GoTo 0

Set OutMail = OutApp.ActiveExplorer.Selection.Item(1)
With OutMail
Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
strText = wdDoc.Application.Selection.Range.Text
End With
MsgBox strText
lbl_Exit:
Set OutMail = Nothing
Set OutApp = Nothing
Set olInsp = Nothing
Set wdDoc = Nothing
Exit Sub
End Sub

gmayor
11-14-2016, 05:56 AM
Assuming the message box gives the result you require, and you are running the code in Excel, then you can simply write strText to the cell in question e.g.

ActiveSheet.Range("A1") = strTextin place of (or after) the MsgBox line.