for example
violation notication - july10
i need only "violation notication"
could you please help me to provide vba code.
thanks
Printable View
for example
violation notication - july10
i need only "violation notication"
could you please help me to provide vba code.
thanks
Don't just copy it ;)
Understand how it works...
Code:Sub Sample()
Dim strString As String, MyArray() As String
strString = "violation notication - july10"
MyArray = Split(strString, "-")
MsgBox Trim(MyArray(0))
End Sub
Hi kool
i have error mismatch myitem i am trying to find subject in outlook
Public Sub ReadOutlook()
Dim strString As String
Dim MyArray() As String
Dim olNamespace As Outlook.Namespace
Dim olItem As MailItem
Dim i As Integer
Dim b As Integer
Dim olfolder As Outlook.MAPIFolder
Dim lngCol As Long
Dim mypasswrd
Dim olMail As Variant
Set OL = GetObject(, "OUTLOOK.APPLICATION")
Set MAPI = OL.GetNamespace("MAPI")
Set Folder = MAPI.Folders("Inbox")
For Each Myitem In Folder.Items
strString = "Violation Notication - "
MyArray = Split(strString, "-")
If Myitem = MyArray Then
MsgBox (Myitem)
Do you want to find if the subject has "Violation Notication - "?
only find the subject violation notification" not -
Code:If Instr( TheStringYouWantToSerachIn, "violation notification") > 0 Then
' it exists
Else
' it doesn't exist
End If
Pradeep
thanks i am captureing information related with the subject "violation notification" to excel
but the subject has '"violation notification - "
i have the code
it does not pick up the "Violation Notication"vb Code:
Public Sub ReadOutlook() Dim strString As String Dim MyArray() As String Dim olNamespace As Outlook.Namespace Dim olItem As MailItem Dim i As Integer Dim b As Integer Dim olfolder As Outlook.MAPIFolder Dim lngCol As Long Dim mypasswrd Dim olMail As Variant Set OL = GetObject(, "OUTLOOK.APPLICATION") Set MAPI = OL.GetNamespace("MAPI") Set Folder = MAPI.Folders("Inbox") For Each Myitem In Folder.Items strString = "Violation Notication - " MyArray = Split(strString, "-") If Myitem = trim(MyArray(0) Then MsgBox (Myitem)
Kamakshi: There was a reason why I asked the question in post 4.
You don't need to use split() to check for the existence of a word(s) in a string. You need to use Instr() as Pradeep suggested. I gave you the split() option based on the query in post 1
Let me give you an example.
Now are you automating Outlook? From Excel or or from Word?Code:#
Set OL = GetObject(, "OUTLOOK.APPLICATION")
What do you exactly want to do if you find an email with the subject that you want?
Don't paste any code yet. Just give me a simple 'flow' of what you want :)
i am automating outlook to excel filtering the only in the subject 'violence notification corresponding sendername received time.
Here is the most simple example I can give you :)
Note: Please set a reference to Outlook Object Library by clicking on the menu Tools--> References and selecting the Microsoft Outlook Object Library.
Edit:Code:'~~> Set reference to Outlook Object Library by clicking on
'~~> Tools-->References and selecting the Microsoft Outlook Object Library
Sub CheckMailInInbox()
Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim Fldr As MAPIFolder
Dim olMail As Variant
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
For Each olMail In Fldr.Items
If InStr(olMail.Subject, "Violation Notication - ") > 0 Then
'~~> I am displaying the entire subject
MsgBox olMail.Subject
'~~> Your code here to do whatever you want
End If
Next olMail
Set Fldr = Nothing
Set olNs = Nothing
Set olApp = Nothing
End Sub
BTW olMail.ReceivedTime will give you the received time of the email and olMail.SenderName will give you the sender's name.
thanks kool it is resolved.
Glad to be of help ;)