-1

I am new in Excel VBA and still trying hard to understand Excel VBA. Am trying to make life easier for my team members.

Appreciate if someone can point me a direction on how to retrieve out text from the currently viewed email and paste the information on a Excel speadsheet.

Email will look something like this.

Name: Tan AK
Contact number: 65-12223456

===================================== Would like to extract out the details

E.g

Cell A1 should display the first sentence
Cell A2 should display the second sentence.

Appreciate if someone can help me out.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
CanP
  • 11

1 Answers1

1

General questions like yours are not popular here. Below I give information that should get you started. If you run into difficulties try a question like this:

I want to achieve A but the half-a-dozen statements below do B. I do not see what I am doing wrong.

Questions which focus on a single issue and demonstrate what you have tried are usually answered very quickly.


The Outlook security system makes it much more difficult for an Excel macro to read from Outlook than for an Outlook macro to write to Excel.

On the other hand, it is much easier to distribute an Excel macro because you can email the workbook to each of your friends and they can immediately use it. With an Outlook macro, you will have to export the module and each friend would then have to import it.

I suggest you start with an Outlook macro. When you have learnt enough to get that macro working to your satisfaction, you may know enough to start exploring the issues of reading from Outlook .


This little Outlook macro show how to access the selected emails:

Option Explicit
Public Sub DemoExplorer()

  Dim Exp As Outlook.Explorer
  Dim ItemCrnt As MailItem
  Dim NumSelected As Long

  Set Exp = Outlook.Application.ActiveExplorer

  NumSelected = Exp.Selection.Count

  If NumSelected = 0 Then
    Debug.Print "No emails selected"
  Else
    For Each ItemCrnt In Exp.Selection
      With ItemCrnt
        Debug.Print "From " & .SenderName & " Subject " & .Subject
      End With
    Next
  End If

End Sub

The Outlook macro in the answer below creates an Excel workbook and exports details of every email in the Inbox to it. This demonstrates many of the techniques you will need. Perhaps more importantly, it shows what the text and html bodies of an email look like to a VBA macro. This will help you split a body into sentences.

How to copy Outlook mail message into excel using VBA or Macros

Community
  • 1
  • 1
Tony Dallimore
  • 12,335
  • 7
  • 32
  • 61