Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2007

Tip: Looking for answers? Try searching our database.

regex request

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mike.spiller@gmail.com - 14 Jun 2007 16:58 GMT
I need to come up with a regex routine that will extract some data
from a file, and I am admittedly lousy with regexes.

The file contents are as such. Either there will be a single entry
such as...
***********************************************
(header info)
1:
Some data (multiline)

-or-

(header info)
1:
Some data (multiline)
2:
More data
etc...
*************************************************
I need to extract just the data in the "1:" section. Can anyone help?
Doug Robbins - Word MVP - 15 Jun 2007 11:51 GMT
I guess by regex you mean macro and that you want the macro to do this on a
group of files.

Need to know exactly how your documents are arranged and also what is to be
done with the extracted information.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>I need to come up with a regex routine that will extract some data
> from a file, and I am admittedly lousy with regexes.
[quoted text clipped - 16 lines]
> *************************************************
> I need to extract just the data in the "1:" section. Can anyone help?
mike.spiller@gmail.com - 15 Jun 2007 14:51 GMT
There is a folder of address files. I will select one at a time via a
filedialog box.
The files look like this. I just need the text after "1:" , i.e.
123 First St.
Seattle, WA
98333,
even if there are several entries.

************************** EXAMPLE ***********************
[ addresses ]

1:
123 First St.
Seattle, WA
98333

**************** OR *******************

[addresses]

1:
123 First St.
Seattle, WA
98333

2:
PO Box 111
Seattle, WA
98114

************************ END ************************
Doug Robbins - Word MVP - 16 Jun 2007 10:00 GMT
With a little bit more information, it would be possible to create a macro
that will go through each file in the folder and extract the first address
from each.

If you open a file and click on the show hide button, does it look like
this:

[addresses]¶

1:¶
123 First St.¶
Seattle, WA¶
98333¶

2:¶
PO Box 111¶
Seattle, WA¶
98114¶

Then, what do you want to do with the

123 First St.
Seattle, WA
98333

When it has been extracted?

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> There is a folder of address files. I will select one at a time via a
> filedialog box.
[quoted text clipped - 27 lines]
>
> ************************ END ************************
mike.spiller@gmail.com - 17 Jun 2007 18:01 GMT
On Jun 16, 2:00 am, "Doug Robbins - Word MVP"
<d...@REMOVECAPSmvps.org> wrote:
> With a little bit more information, it would be possible to create a macro
> that will go through each file in the folder and extract the first address
[quoted text clipped - 68 lines]
>
> - Show quoted text -

I will eventually be taking that text, and put it into a visio shape.
Doug Robbins - Word MVP - 17 Jun 2007 20:39 GMT
Is:

- Show quoted text -

the answer to the first question?

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

On Jun 16, 2:00 am, "Doug Robbins - Word MVP"
<d...@REMOVECAPSmvps.org> wrote:
> With a little bit more information, it would be possible to create a macro
> that will go through each file in the folder and extract the first address
[quoted text clipped - 69 lines]
>
> - Show quoted text -

I will eventually be taking that text, and put it into a visio shape.
mike.spiller@gmail.com - 18 Jun 2007 14:28 GMT
On Jun 17, 12:39 pm, "Doug Robbins - Word MVP"
<d...@REMOVECAPSmvps.org> wrote:
> Is:
>
[quoted text clipped - 93 lines]
>
> - Show quoted text -

Yes, the plan is to extract the address out of a file and have it end
up in a Visio flowchart shape.
Russ - 18 Jun 2007 18:52 GMT
Mike,
This is the first question that Doug is waiting for you to answer.

Quote:

If you open a file and click on the show hide button, does it look like
this:

[addresses]¶

1:¶
123 First St.¶
Seattle, WA¶
98333¶

2:¶
PO Box 111¶
Seattle, WA¶
98114¶

Unquote:

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

mike.spiller@gmail.com - 19 Jun 2007 02:40 GMT
On Jun 18, 10:52 am, Russ <drsN0SPAMmi...@hotmailD0Tcom.INVALID>
wrote:
> Mike,
> This is the first question that Doug is waiting for you to answer.
[quoted text clipped - 22 lines]
>
>  drsmN0SPAMikleAThotmailD0Tcom.INVALID

yes, that's exactly how it looks.
Doug Robbins - Word MVP - 23 Jun 2007 08:06 GMT
The following code will extract the first address from all of the documents
in a folder (if each document is formatted as you indicated and it will
insert them into a new file.  You will have to come up with your own code
for the Visio part of it.

Dim MyPath As String
Dim MyName As String
Dim source As Document, target As Document
Dim addr As Range
Dim i As Long
'Create a new document to contain the addresses
Set target = Documents.Add
'let user select a path
With Dialogs(wdDialogCopyFile)
   If .Display() <> -1 Then Exit Sub
   MyPath = .Directory
End With
'strip quotation marks from path
If Len(MyPath) = 0 Then Exit Sub
If Asc(MyPath) = 34 Then
   MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If
'get files from the selected path
'and extract the first address
'and insert it into the target document
MyName = Dir$(MyPath & "*.*")
Do While MyName <> ""
   Set source = Documents.Open(MyName)
   i = 1
   With source
       Set addr = .Paragraphs(4).Range
       While Len(.Paragraphs(4 + i).Range) > 1
           addr.End = .Paragraphs(4 + i).Range.End
           i = i + 1
       Wend
   End With
   target.Range.InsertAfter addr & vbCr
   source.Close wdDoNotSaveChanges
Loop

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

On Jun 18, 10:52 am, Russ <drsN0SPAMmi...@hotmailD0Tcom.INVALID>
wrote:
> Mike,
> This is the first question that Doug is waiting for you to answer.
[quoted text clipped - 22 lines]
>
>  drsmN0SPAMikleAThotmailD0Tcom.INVALID

yes, that's exactly how it looks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.