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
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