Results 1 to 12 of 12

Thread: [RESOLVED] Extract words After -

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Resolved [RESOLVED] Extract words After -

    for example
    violation notication - july10
    i need only "violation notication"
    could you please help me to provide vba code.
    thanks

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Extract words After -

    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
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Re: Extract words After -

    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)

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Extract words After -

    Do you want to find if the subject has "Violation Notication - "?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Re: Extract words After -

    only find the subject violation notification" not -

  6. #6
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Extract words After -

    Code:
    If Instr( TheStringYouWantToSerachIn, "violation notification") > 0 Then
        ' it exists
    Else
        ' it doesn't exist
    End If
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Re: Extract words After -

    Pradeep
    thanks i am captureing information related with the subject "violation notification" to excel
    but the subject has '"violation notification - "
    i have the code
    vb Code:
    1. Public Sub ReadOutlook()
    2.  
    3. Dim strString As String
    4. Dim MyArray() As String
    5. Dim olNamespace As Outlook.Namespace
    6. Dim olItem As MailItem
    7. Dim i As Integer
    8. Dim b As Integer
    9.  
    10. Dim olfolder As Outlook.MAPIFolder
    11. Dim lngCol As Long
    12. Dim mypasswrd
    13. Dim olMail As Variant
    14.  
    15. Set OL = GetObject(, "OUTLOOK.APPLICATION")
    16. Set MAPI = OL.GetNamespace("MAPI")
    17.  
    18. Set Folder = MAPI.Folders("Inbox")
    19. For Each Myitem In Folder.Items
    20. strString = "Violation Notication - "
    21. MyArray = Split(strString, "-")
    22. If Myitem = trim(MyArray(0) Then
    23. MsgBox (Myitem)
    it does not pick up the "Violation Notication"

  8. #8
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Extract words After -

    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.

    Code:
    #
    Set OL = GetObject(, "OUTLOOK.APPLICATION")
    Now are you automating Outlook? From Excel or or from Word?

    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
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Re: Extract words After -

    i am automating outlook to excel filtering the only in the subject 'violence notification corresponding sendername received time.

  10. #10
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Extract words After -

    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.

    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
    Edit:

    BTW olMail.ReceivedTime will give you the received time of the email and olMail.SenderName will give you the sender's name.
    Last edited by Siddharth Rout; Jul 21st, 2010 at 07:35 AM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Re: [RESOLVED] Extract words After -

    thanks kool it is resolved.

  12. #12
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [RESOLVED] Extract words After -

    Glad to be of help
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width