- Joined
- Nov 11, 2017
- Messages
- 5
- Reaction score
- 0
Hello
I’m looking for a macro that will extract
Name, address and phone numbers
from a RAW DATA file.
Attached is the RAW DATA file.
Sample RAW Data block ( in the data file ) where text can be search and extracted.
----------------------------------------------------------------------------------------------------
Melanie Pursglove </a>
</h3>
<div class="c-people-result__address">5720 Premier Park DR, West Palm Beach, FL 33407</div>
<div class="c-people-result__phone">(412) 264-6619</div>
The best way to handle this I think is to search for phone number in word as (^?^?^?) ^?^?^?-^?^?^?^? format and once that format is found then go up to the name area and extract the whole block of text in a new document and then once all of them are extracted then with the SEARCH and REPLACE cleanup the extra raw data.
I was able to write a macro doing above, but the whole macro takes up about ½ hr and that’s too much.
A friend wrote this macro USING RANGES for extracting data from a financial document and it works REALLY FAST.
I was wondering if anyone has any knowledge about RANGES and modify the following macro to extract the
Name, address and phone numbers
From the attached RAW DATA file.
Thanks.
Macro that was written. USING RANGES
---------------------------------------------------
Option Explicit
Sub Macro1()
Dim oDoc As Document
Dim oNewDoc As Document
Dim oRng As Range, oRng2 As Range, oFound As Range
Dim vFind As Variant
Dim fso As Object
Dim strPath As String
Const strFind As String = "Add to watchlist|TOTAL REVENUE"
strPath = Environ("USERPROFILE") & "\Desktop\DataExtract.doc" 'The name of the document to save the extract
Set fso = CreateObject("Scripting.FileSystemObject")
vFind = Split(strFind, "|")
Set oDoc = ActiveDocument
If fso.FileExists(strPath) Then
Set oNewDoc = Documents.Open(FileName:=strPath, AddToRecentFiles:=False)
Else
Set oNewDoc = Documents.Add
oNewDoc.SaveAs FileName:=strPath
End If
Set oRng = oDoc.Range
With oRng.Find
Do While .Execute(FindText:=vFind(0))
oRng.MoveStart wdParagraph, -2
oNewDoc.Range.InsertAfter _
Left(oRng.Paragraphs(1).Range.Text, _
Len(oRng.Paragraphs(1).Range.Text) - 1)
Set oFound = oRng
oFound.End = oDoc.Range.End
With oFound.Find
Do While .Execute(FindText:=vFind(1))
oFound.End = oFound.Paragraphs(1).Range.End - 1
Set oRng2 = oNewDoc.Range
oRng2.End = oRng2.End - 1
oRng2.Collapse 0
oRng2.Text = vbTab & oFound.Text & vbCr
oRng.Collapse 0
Exit Do
Loop
End With
oRng.Collapse 0
Loop
End With
With oNewDoc.Range
.ParagraphFormat.TabStops.ClearAll
.ParagraphFormat.TabStops.Add CentimetersToPoints(6.5)
.ParagraphFormat.SpaceAfter = 0
.Font.Name = "Arial"
.Font.Size = 8
End With
'oNewDoc.Close wdSaveChanges 'Optional
lbl_Exit:
Set fso = Nothing
Set oDoc = Nothing
Set oNewDoc = Nothing
Set oRng = Nothing
Set oRng2 = Nothing
Set oFound = Nothing
Exit Sub
End Sub
I’m looking for a macro that will extract
Name, address and phone numbers
from a RAW DATA file.
Attached is the RAW DATA file.
Sample RAW Data block ( in the data file ) where text can be search and extracted.
----------------------------------------------------------------------------------------------------
Melanie Pursglove </a>
</h3>
<div class="c-people-result__address">5720 Premier Park DR, West Palm Beach, FL 33407</div>
<div class="c-people-result__phone">(412) 264-6619</div>
The best way to handle this I think is to search for phone number in word as (^?^?^?) ^?^?^?-^?^?^?^? format and once that format is found then go up to the name area and extract the whole block of text in a new document and then once all of them are extracted then with the SEARCH and REPLACE cleanup the extra raw data.
I was able to write a macro doing above, but the whole macro takes up about ½ hr and that’s too much.
A friend wrote this macro USING RANGES for extracting data from a financial document and it works REALLY FAST.
I was wondering if anyone has any knowledge about RANGES and modify the following macro to extract the
Name, address and phone numbers
From the attached RAW DATA file.
Thanks.
Macro that was written. USING RANGES
---------------------------------------------------
Option Explicit
Sub Macro1()
Dim oDoc As Document
Dim oNewDoc As Document
Dim oRng As Range, oRng2 As Range, oFound As Range
Dim vFind As Variant
Dim fso As Object
Dim strPath As String
Const strFind As String = "Add to watchlist|TOTAL REVENUE"
strPath = Environ("USERPROFILE") & "\Desktop\DataExtract.doc" 'The name of the document to save the extract
Set fso = CreateObject("Scripting.FileSystemObject")
vFind = Split(strFind, "|")
Set oDoc = ActiveDocument
If fso.FileExists(strPath) Then
Set oNewDoc = Documents.Open(FileName:=strPath, AddToRecentFiles:=False)
Else
Set oNewDoc = Documents.Add
oNewDoc.SaveAs FileName:=strPath
End If
Set oRng = oDoc.Range
With oRng.Find
Do While .Execute(FindText:=vFind(0))
oRng.MoveStart wdParagraph, -2
oNewDoc.Range.InsertAfter _
Left(oRng.Paragraphs(1).Range.Text, _
Len(oRng.Paragraphs(1).Range.Text) - 1)
Set oFound = oRng
oFound.End = oDoc.Range.End
With oFound.Find
Do While .Execute(FindText:=vFind(1))
oFound.End = oFound.Paragraphs(1).Range.End - 1
Set oRng2 = oNewDoc.Range
oRng2.End = oRng2.End - 1
oRng2.Collapse 0
oRng2.Text = vbTab & oFound.Text & vbCr
oRng.Collapse 0
Exit Do
Loop
End With
oRng.Collapse 0
Loop
End With
With oNewDoc.Range
.ParagraphFormat.TabStops.ClearAll
.ParagraphFormat.TabStops.Add CentimetersToPoints(6.5)
.ParagraphFormat.SpaceAfter = 0
.Font.Name = "Arial"
.Font.Size = 8
End With
'oNewDoc.Close wdSaveChanges 'Optional
lbl_Exit:
Set fso = Nothing
Set oDoc = Nothing
Set oNewDoc = Nothing
Set oRng = Nothing
Set oRng2 = Nothing
Set oFound = Nothing
Exit Sub
End Sub