Auto formatting letters

M

mavruss

Here is the situation.
We have an in house program that generates multiple letters in one file.
This is raw MSDOS data. The issue is that the letters aren’t being formatted
correctly anymore. So, what I have been doing is manually going in and making
the changes.
I started using a macro to change the font but I can’t figure out the other
issue.
What happens is the letters are bleeding from one page break into the next.
For example, letter one’s signature is on letter two’s header.

Any ideas? If I could set up the macro to start text at the header margin
that might work but I don’t have any idea how to set that up.

Thanks in advance!
 
G

Graham Mayor

Your description of the document is too vague to be of any help. However, if
you can identify where each 'letter' finishes replace the 'page break' there
with a next page section break.

You do however say that this is 'raw MSDOS' data, which implies a plain text
file, so it is difficult to see how this may include 'headers' unsupported
by plain text.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

mavruss

The program generates one file that contains multiple letters that are in
plain text. The file changes from day to day. One day, the file may have 3
letters. The next day it may be 50 letters. What I have been doing is opening
word and formatting each letter.
The best way I can describe what is happening is it seems that as the
letters are created, the text seems to “travel†down the pages. So I end up
having text from letter one (like the signature) end up being at the
beginning of the next letter.
What I have been doing is using a macro that adjusts the font and margins.
Then I use the backspace key to remove large empty spaces to move the text
back to where it belongs.
 
D

Doug Robbins - Word MVP

Where is the data coming from that makes each of the 3 or 50 letters unique?
It sounds like you might be able to use Mail Merge to create each individual
letter.

--
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, originally posted via msnews.microsoft.com
 
G

Graham Mayor

A start might be to search for the signature, which presumably ends each
'letter' and insert a section break after it, then remove the white space at
the top of the next 'letter'. Something like

Dim sSignature As String
Dim oRng As Range
Dim oSection As Section
sSignature = "Graham Mayor" 'replace with your sig
With Selection
.HomeKey wdStory
Do While .Find.Execute(findText:=sSignature) = True
Set oRng = Selection.Range
oRng.Collapse wdCollapseEnd
oRng.InsertBreak wdSectionBreakNextPage
Loop
End With
ActiveDocument.Undo 1
For Each oSection In ActiveDocument.Sections
Do Until Len(oSection.Range.Paragraphs(1).Range) > 1
oSection.Range.Paragraphs(1).Range.Delete
Loop
Next oSection

http://www.gmayor.com/installing_macro.htm

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

mavruss

Graham,
Thanks for the help. The code found the end of the letters but it didnt
change anything. Let me insert an example of the letters:



03/16/10
ADDRESS HERE
ADDRESS HERE






RE: ORDER NUMBER XXXXX
ORDER DATE 03/16/10


THANK YOU FOR ORDERING FROM OUR COMPANY
A REFUND IN THE AMOUNT OF $xx.xx IS CURRENTLY BEING PROCESSED.
YOU SHOULD RECEIVE YOUR REFUND IN THE NEXT FEW WEEKS. IF YOU
DO NOT RECEIVE YOUR REFUND PLEASE CONTACT OUR CUSTOMER SERVICE
DEPARTMENT.

CANCEL PRODUCT NAME
NOT ENOUGH MONEY SENT














SINCERELY,


NAME
CUSTOMER SERVICE REPRESENTATIVE












-----------------------PAGE BREAK----------------------------------------






03/16/10
ADDRESS HERE
ADDRESS HERE






RE: ORDER NUMBER XXXXX
ORDER DATE 03/16/10


THANK YOU FOR ORDERING FROM COMPANY NAME
A REFUND IN THE AMOUNT OF $XX.XXIS CURRENTLY BEING PROCESSED.
YOU SHOULD RECEIVE YOUR REFUND IN THE NEXT FEW WEEKS. IF YOU
DO NOT RECEIVE YOUR REFUND PLEASE CONTACT OUR CUSTOMER SERVICE
DEPARTMENT.

CANCEL PRODUCT NAME-



---------------------PAGE BREAK---------------------------











SINCERELY,


NAME
CUSTOMER SERVICE REPRESENTATIVE




AS you can see, the first letter was for the most part ok but the page break
was in the wrong spot on the second letter. I'll try to run the code again.
Please forgive me as im new to programming( In fact, I just started to read a
beginners guide to c# programming).

Also, I really appreciate you help in this.

-Russ Keller
IT Support
 
M

mavruss

The program was custom built in house written in magic. the developer isnt
willing to recode to format the letters so, here I am dealing with the
situation.
 
G

Graham Mayor

Is the text -
-----------------------PAGE BREAK----------------------------------------
included in the original text document or is that something *you* have
included for the purpose of example?
If it is included in the original document then the following version of the
macro will replace that text with a next page section break.

Dim sSignature As String
Dim oRng As Range
Dim oSection As Section
sSignature = "PAGE BREAK"
ActiveDocument.Range = Replace(ActiveDocument.Range, Chr(11), Chr(13))
ActiveDocument.Range.ParagraphFormat.SpaceAfter = 0
With Selection
.HomeKey wdStory
Do While .Find.Execute(findText:=sSignature) = True

Set oRng = Selection.Paragraphs(1).Range
oRng.Delete
oRng.InsertBreak wdSectionBreakNextPage
Loop
End With
ActiveDocument.Undo 1

If it is something added by you then use the following version to add the
section breaks


Dim sSignature As String
Dim oRng As Range
Dim oSection As Section
sSignature = "CUSTOMER SERVICE REPRESENTATIVE"
ActiveDocument.Range = Replace(ActiveDocument.Range, Chr(11), Chr(13))
ActiveDocument.Range.ParagraphFormat.SpaceAfter = 0
With Selection
.HomeKey wdStory
Do While .Find.Execute(findText:=sSignature) = True
Set oRng = Selection.Range
oRng.Collapse wdCollapseEnd
oRng.InsertBreak wdSectionBreakNextPage
Loop
End With
ActiveDocument.Undo 1
For Each oSection In ActiveDocument.Sections
Do Until Len(oSection.Range.Paragraphs(1).Range) > 1
oSection.Range.Paragraphs(1).Range.Delete
Loop
Next oSection

I have added a line to each to replace line breaks with paragraph breaks to
ensure that the lines break where required.

If that doesn't fix it, you will have to send me a sample of the original
document (with names changed to maintain confidentiality) to the link on the
home page of my web site.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

mavruss

I put the" --------page break------ "for the example. Its just blank space
otherwise.
 
M

mavruss

GRAHAM!
Yor awsome man! It totally worked! I added some other stuff like margin
adjusting and font size.
Now I just need to go install office 2007 on the end users workstations!

Thanks again! your a life saver!

-Russ
IT Support
 
D

Doug Robbins - Word MVP

I would forget about C# programming. As suggested earlier, you should
investigate the use of mail merge to create the letters. From where is the
variable data for each letter coming?

--
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, originally posted via msnews.microsoft.com
 
G

Graham Mayor

You are welcome :)

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

mavruss

Oh, Im not learning c# for this. I have a little knowledge of Sharepoint and
want to make some custome web apps for it.
 

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