Hey Gmayor,
I've made a few changes and i'm able to meet my requirements on finding the email and editing the subject without saving the changes to the subject but direct printing, what i'm left with is getting these searches of SO Number in sequence of A2, A3 and corresponding invoice number getting pasted into the subject as B2 , B3... respectively.
Option Explicit
Public Sub Test_sofWorkWithOutlook()
Dim olApp As Object
Dim olNs As Object
Dim olFldr As Object
Dim olMail As Object
Dim olInsp As Object
Dim wdDoc As Object
Dim oRng As Object
Dim strNum As String
Dim strNum1 As String
Dim xlSheet As Worksheet
Dim LastRow As Long, lngRow As Long
Dim Subject As Long
Dim LastRow1 As Long, lngRow1 As Long
'Set olApp = outlookApp()
Set olApp = GetObject(, "Outlook.Application")
Set olNs = olApp.GetNamespace("MAPI")
Set olFldr = olNs.GetDefaultFolder(6)
Set xlSheet = ActiveSheet
With xlSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
LastRow1 = .Cells(.Rows.Count, "B").End(xlUp).Row
For lngRow = 1 To LastRow
For lngRow1 = 1 To LastRow1
strNum = .Cells(LastRow, 1)
strNum1 = .Cells(LastRow1, 1)
For Each olMail In olFldr.Items
If TypeName(olMail) = "MailItem" Then
If (InStr(1, olMail.Subject, strNum, vbTextCompare) > 0) Then
With olMail
Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor 'access the message body for editing
Set oRng = wdDoc.Range 'orng is the message body
.Subject = olMail.Subject & " " & strNum1
'.Display
'edit oRng as required
'.Save
.PrintOut
Exit For
End With
End If
End If
DoEvents
Next olMail
DoEvents
Next lngRow1
Next lngRow
End With
Set olMail = Nothing
Set olFldr = Nothing
Set olNs = Nothing
Set olApp = Nothing
End Sub
i'm unable to run this in loop, your code only searches for the last row subject in the column A as seen in the code which is not what i wish to achieve.
thank you.
couldn't edit the earlier reply hence adding a new reply