How do I pull info from Header?

M

MikeZz

I have an "rtf" file that I scan for details unsing an Excel Macro so that
the entire file can be summarized into an easy to view excel file.

The next step for me to do is use VBA to extract various Header/Footer
details from the rtf file. All the header info is the same for every page
(just repeats), and the footer detail may be different... such as "page 20 of
30".

An example of the page header would be:

Change Number: 123454 Date: 2/6/2008 Part Number: 123498
Supplier: A-Company

Is there a way to use VBA to read in the header and break it apart into
known fields?

As I mentioned, I will actually be using Excel VBA to do the work if that
makes any difference.

Thanks,
MikeZz
 
G

Graham Mayor

This forum is for Word vba and I know only the rudiments of Excel
programming (which has its own forum)- however the following will read the
main header from your RTF document using Word vba and (assuming the wording
and spacing between the elements in your example) extract from it the
various items of data it contains. It allows for variable length dates and
company names, but only extracts six digit numbers as written into four
variables. .

Dim oHeader As Range
Dim sCNumber As String
Dim sDate As String
Dim sPartNo As String
Dim sSupp As String
Set oHeader =
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
sCNumber = Mid(oHeader, InStr(oHeader, "Number") + 9, 6)
sDate = Mid(oHeader, 35, InStr(oHeader, "Part") - 35)
sPartNo = Mid(oHeader, InStr(oHeader, "Part") + 14, 6)
sSupp = Mid(oHeader, InStr(1, oHeader, "Supplier") + 11, _
Len(oHeader) - InStr(1, oHeader, "Supplier"))
MsgBox sCNumber & vbCr _
& sDate & vbCr _
& sPartNo & vbCr _
& sSupp


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top