Save document according to file in certain location

J

Jason

Hi. I am trying to develop a macro for a user who wants
to have a macro that automatically merges an access file
with a letter shell. After it has finished merging, she
then wants each letter printed and saved in separate
files. She also wants each letter to be saved according
to a project number, which is located in the final merged
document. I assume she may have anywhere from 5 to 50
letters that need to be printed, divided and saved. I
need the macro to move to the location of the project
number in the document, choose extend:=wdExtend, and then
do a save as, or something like that. Essentially, I need
the letters split into individual letters, printed, and
saved according to this project number.

Here is some code I have used for another project that
involves splitting the document:
Dim fname As String, i As Integer, Source As Document,
Target As Document
Set Source = ActiveDocument
For i = 1 To Source.Paragraphs.Count
Set Target = Documents.Add

Target.Range = Source.Paragraphs(i).Range
Selection.Find.Execute Replace:=wdReplaceAll
----> I think it should move six down, but each time I
have tried, it stays in the same line, but it moves to the
right six times:
Selection.MoveDown Unit:=wdStory, Count:=6,
Extend:=wdExtend
--->the project number contains dashes
Selection.MoveUntil Cset:="-"
Selection.MoveLeft Unit:=wdCharacter, Count:=5,
Extend:=wdExtend

fname = Selection
Target.SaveAs FileName:=fname & ".doc"
---> Target.Print (? - not sure about this)
Target.Close
Set Target = Nothing

Next i

Set Source = Nothing


End Sub

If you have any code suggestions, I'd appreciate it. I
know the above is quite off in some areas, but that's
because I have been experimenting a lot.

TIA,
Jason
 
J

Jason

Helmut,

Thanks much! This helps loads!!! Yeah, forgot to take
that search execute line out before I sent it on to the
list. I am still a newbie VBA programmer, too. Thanks
again!

-Jason
 
J

Jason

Helmut,

As I said, that was really helpful for splitting and
saving the letter file separately, but I am still
struggling with how to grab this specific number area and
save the document as that particular number. Here is how
the beginning of each letter looks:

June 6, 2003 NOTICE OF AWARD


ABC Co
123 Happy Road
Chatham, IL 62629


RE: CDB Project No. 815-156-578
CDB Contract No. 58965
Poducnk, Illinois



I need the CDB Project No. selected and whatever that
number is will be the name of the letter. This process is
the same for 3 different forms as well.

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