Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default macro to open the mail and copy the data to excel

I'm about 3/4 of the way there. I'm tyring to learn Outlook features in VBA.
I got the latest message but trying to figure out how to read the body of
the message.

There are 3 things you need to do
1) To the VBA reference add Outlook object
VBA menu Tools - References - Microsoft Outlook 10.o Object Library - Check
box and press Add. Use the latest version that is on your computer.

2) You need to Insert (from Inset VBA menu) a Class Module to you VBA
project called Class1. I'm using AdvanceSearch which is looking at your
inbox and finding the messages received today with LOCK in the subject.
AdvanceSearch triggers an event that can only be recognized in a class
module. The Class module when an event occurs sets blnSearchComp TRUE and
trigger the DoEvent in the module code. Add this code to the class module

Public WithEvents olApp As Outlook.Application
Private m_sch As Outlook.Search
Public Sub AdvSearch(MyScope As String, MyFilter As String, _
ByRef m_sch)
Set m_sch = olApp.AdvancedSearch(MyScope, MyFilter)
End Sub
Private Sub Class_Initialize()
Set Me.olApp = CreateObject("Outlook.Application")
Set myNamespace = Me.olApp.GetNamespace("MAPI")
Set myfolder = myNamespace.GetDefaultFolder(olFolderInbox)
End Sub
Private Sub Class_Terminate()
Set Me.olApp = Nothing
End Sub
Private Sub olApp_AdvancedSearchComplete(ByVal SearchObject As Outlook.Search)
blnSearchComp = True
End Sub



3) This code is the module code where all your programming can be written.
the code calls the Class1 modules to initialize the search. Add the code to
a regular Module (not a class module).


Public blnSearchComp As Boolean
Public g_clsTest As Class1
Sub GetMail()

Const strS As String = "Inbox"
Dim strF As String
Dim sch As Outlook.Search
Dim rsts As Outlook.Results



strF = "urn:schemas:httpmail:" & _
"subject LIKE '%Lock%' AND" & _
"%today(urn:schemas:httpmail:datereceived)%"


blnSearchComp = False
Set g_clsTest = New Class1
g_clsTest.AdvSearch strS, strF, sch


While blnSearchComp = False
DoEvents
Wend

Set rsts = sch.Results
rsts.Sort "ReceivedTime", Descending:=True
Set LastestMess = rsts.Item(1)


End Sub


"Ranjit kurian" wrote:

i need a macro to open the lastest (for that day) outlook mail in inbox which
has subject begins with Lock and in that mail there is a table with four
columns, the macro should go to column called as Net and add the
amount(amount is given below the heading) with next column called as Gross
(amount is given below the heading) and paste in excel active cell.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Open file to run Mail macro nospaminlich Excel Programming 1 October 23rd 06 08:20 PM
Using Currently Open Lotus Notes Mail Server Info in Excel Macro Scottms Excel Programming 0 June 27th 06 07:55 PM
Macro to automatically open a website or send an e-mail in excel Byron Excel Discussion (Misc queries) 3 April 7th 06 09:05 AM
Macro to Copy data from e-mail and paste it into a field on a website joebobcletusjr Excel Programming 0 February 16th 05 05:19 PM
Excel macro to open word mail merge Chad Excel Programming 0 May 30th 04 01:06 AM


All times are GMT +1. The time now is 05:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"