Removing and replacing paragraph marks

J

Jason

Hi,

I am creating a macro that will take a text file of many
records separated by section breaks. This file comes from
Wordperfect, so instead if Endfields, I have paragraph
marks. I need to make this file into a data source for
different shell docs. So far I have a macro that replaces
all the paragraph marks with tab characters (I would use
commas, but there are commas in the records already for
monetary amounts), then the macro replaces each section
break with a paragraph mark. Finally, the macro types the
fields that will be used as the headings for the data
source. The only problem I am running into now is that
the final data field has a paragraph marker after it, so
when I have that replaced with a tab character it produces
more fields than are in the header. This is a problem
with the final merge because it says there are too many
fields. Is there a way create a macro that will go to the
final line of the record and remove only that one
paragraph marker while keeping the section break? Here is
what it looks like before conversion:

046<p>
Mr. John Doe, Superintendent<p>
Community Unit School District 1<p>
1212 State<p>
Springfield, MO 62360<p>
<p>
Hannel<p>
772-001-003/S03<p>
construction of an addition to the Elementary School for
160 students in PreK-6th grades, along with health, life-
safety improvements to the 1917 and 1921 portions of the
school determined to be functionally over 100 years old<p>
#,###,553<p>
#,###,031<p>
###,522<p>
01 elementary grant index of .733019<p>
093<p>
47<p>
Adams<p>
Payson Community Unit School District 1<p><section break>

The macro I have created so far converts the file into this

Field1<t>Field2<t>Field3<t>, and so on
Mr.John Doe, Superintendant<t>Community School<t>and so on

The files range in size from 11 records to 73. Any help
would be much appreciate.

TIA,
Jason
 
D

Doug Robbins - Word MVP

Hi Jason,

Use

Dim arange As Range
Set arange = ActiveDocument.Range
arange.Start = arange.End - 2
arange.End = arange.End - 1
arange.Delete

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
H

Helmut Weber

Hi Jason,
I think, better than inserting a tab and removing
it afterwards, it would be too exclude the last paragraph
from being replaced, and make sure, beforehand,
that there aren't two or more paragraphs marks
at the end of the document. This first task can be
completed by:
Public Sub PurgeDocEnd_V2()
Dim z As Long
With ActiveDocument.Range
z = .End
Set rngTmp = .Range(z - 2, z - 1)
While rngTmp.Text = " " Or rngTmp.Text = Chr$(13)
rngTmp.Delete
z = .Range.End
Set rngTmp = .Range(z - 2, z - 1)
Wend
End With
End Sub
For the following find and replace I would recommend
to define a range that excludes the last paragraph-marker.
Sub Test444()
Dim aRng As Range
With ActiveDocument
Set aRng = .Range
aRng.End = .Range.End - 1
aRng.Select ' if You would like to use selection.find
End With
End Sub
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
 
J

Jason

Doug,

That was close to what I wanted. I think I should have
simplified what I wanted. Basically, I needed code that
would go through each record until it hit the section
break, which divides each record, and backspace/remove the
final field delimiter (a tab space), which appears right
before the section break. This process would need to be
repeated throughout the document until all final field
delimiters are deleted.

Does that clarify my needs more? The macro below got rid
of the final field delimiter on the final record, but
that's it. I might have missed something, though.

TIA,
Jason
 

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