+ Reply to Thread
Results 1 to 3 of 3

Get the text after ABCD in the word header!

Hybrid View

devpp Get the text after ABCD in... 06-12-2015, 02:39 AM
macropod Re: Get the text after ABCD... 06-12-2015, 05:59 AM
devpp Re: Get the text after ABCD... 06-12-2015, 07:37 AM
  1. #1
    Registered User
    Join Date
    12-27-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2007
    Posts
    60

    Get the text after ABCD in the word header!

    Hi all,
    I have a word document in which there is a header.
    The header contents are

    Procedure No. PPRSON-875

    SADSDDSA ASDAERA
    Prepared By: DAEDF TRTFDS Dasegfhfg
    Page 2 of 3 Revision Date: 20150612
    The script which I am using to get the entire content is
    Sub SearchHeader()
    Dim rng As Range
    Dim intSecCount, intSection As Integer
    Dim intHFType As Integer
    intSecCount = ActiveDocument.Sections.Count
    For intSection = 1 To intSecCount
        With ActiveDocument.Sections(intSection)
            For intHFType = 1 To 3
                Set rng = ActiveDocument.Sections(1).Headers(intHFType).Range
                rng.Find.Execute findtext:="Procedure No.", Forward:=True
                If rng.Find.Found = True Then
                    Debug.Print "Match"
                End If
            Next intHFType
        End With
    Next intSection
    End Sub
    My requirement is this
    I just want the "PPRSON-875" which is after the Procedure No : from the header text.
    I have done some coding in excel but for word I am pretty new.
    Can any of guys help me on this.?
    Thanks to the author of the code.

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,835

    Re: Get the text after ABCD in the word header!

    Try:
    Sub SearchHeader()
    Dim i As Long, j As Long, StrPref As String
    StrPref = "Procedure No. "
    With ActiveDocument
      For i = 1 To .Sections.Count
        With .Sections(i)
          For j = 1 To 3
            With .Headers(j).Range
              With .Find
                .Text = StrPref & "[!^13]@^13"
                .Forward = True
                .MatchWildcards = True
                .Execute
              End With
              If .Find.Found = True Then
                MsgBox Mid(.Text, Len(StrPref) + 1, Len(.Text) - Len(StrPref) - 1)
              End If
            End With
          Next
        End With
      Next
    End With
    End Sub
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Registered User
    Join Date
    12-27-2012
    Location
    Chennai
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Get the text after ABCD in the word header!

    Dear Paul Edstein,
    Thanks for the code.
    It worked well.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 6
    Last Post: 09-13-2013, 01:29 AM
  2. Using EXCEL VBA to create word ,insert header in word, add textbox in header and fill pic
    By xiaorenwuhyl in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-28-2013, 05:32 AM
  3. How to get Word Header Text into Excel VBA
    By MikeZz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-23-2006, 04:10 AM
  4. IsPossible to rename header ABCD row?
    By rtf500 in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 01-08-2006, 08:24 AM
  5. Tranferring Text from Excel to a Header in Word
    By Mike in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-24-2005, 12:48 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1