Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Marcus Marcus is offline
external usenet poster
 
Posts: 31
Default Mail Merge Macro Help


1 ) I have a mail merge function that constantly adds an extra page to the
resulting documents I have read eqarlier posts here and followed them but Im
still getting the extra page.

2) How do I stop the document flickering Ive added code that Ive used for
stopping flickering but it still does it the document is about 300 letters It
would be nice to make this mail merge cleaner.

3) one of the main problems is I need to send the original template to
another office so they can use it how do I get the macro from the template to
the newly created Letters document so they can split it. On my machine the
macro is there but when they follow the steps I have given them the macro is
not there on the newly created document which is then menat to be split.

The Code :-

Sub RunME()

Dim Title As String
Dim Default As String
Dim MyText As String
Dim MyName As Variant
Dim MyPath As String


Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1

Default = "Insider List"
MyText = "Enter any extra text to be included in the resulting filenames.
Long filenames may be used."
Title = "File Name"
MyName = InputBox(MyText, Title, Default)

Default = "C:\Documents and Settings\\test"
Title = "Destination Path"
MyText = "Enter a destination path e.g C:"
MyPath = InputBox(MyText, Title, Default)
If MyPath = "" Then
End
End If

' prevent any flickering
Application.ScreenUpdating = False

While Counter Letters
With Selection

.HomeKey Unit:=wdStory
.EndKey Unit:=wdLine, Extend:=wdExtend
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend

End With
sName = Selection
Docname = MyPath & "\" & MyName & "." & sName & "_" & LTrim$(Str$(Counter))
& ".doc"

ActiveDocument.Sections.First.Range.Cut
Documents.Add
With Selection
.Paste
.HomeKey Unit:=wdStory
.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
.Delete
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Wend

' prevent any flickering
Application.ScreenUpdating = True
End Sub


Many Thanks



  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Mail Merge Macro Help

Here is how to do it without getting the blank page at the end of each
document:

Dim i As Long, Source As Document, Target As Document, Letter As Range
Set Source = ActiveDocument
For i = 1 To Source.Sections.Count
Set Letter = Source.Sections(i).Range
Set Target = Documents.Add
Target.Range = Letter
Target.Sections(2).PageSetup.SectionStart = wdSectionContinuous
Target.SaveAs FileName:="Letter" & i
Target.Close
Next i

To make this available to your users, you should create a template in which
you create the macro and send that template to the users and have them save
it in their Word Startup folder. It will then be available to them whenever
they need it.

Also See the "Individual Merge Letters" item on fellow MVP Graham Mayor's
website at:

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

If you are using Word XP or later, the "Add-in to Merge Letters to Separate
Files" that I have written and that can be downloaded from that site will
allow you to create each letter as a separate file with a filename taken
from a field in the data source with a minimum of fuss.





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

"Marcus" wrote in message
...

1 ) I have a mail merge function that constantly adds an extra page to the
resulting documents I have read eqarlier posts here and followed them but
Im
still getting the extra page.

2) How do I stop the document flickering Ive added code that Ive used for
stopping flickering but it still does it the document is about 300 letters
It
would be nice to make this mail merge cleaner.

3) one of the main problems is I need to send the original template to
another office so they can use it how do I get the macro from the template
to
the newly created Letters document so they can split it. On my machine the
macro is there but when they follow the steps I have given them the macro
is
not there on the newly created document which is then menat to be split.

The Code :-

Sub RunME()

Dim Title As String
Dim Default As String
Dim MyText As String
Dim MyName As Variant
Dim MyPath As String


Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1

Default = "Insider List"
MyText = "Enter any extra text to be included in the resulting filenames.
Long filenames may be used."
Title = "File Name"
MyName = InputBox(MyText, Title, Default)

Default = "C:\Documents and Settings\\test"
Title = "Destination Path"
MyText = "Enter a destination path e.g C:"
MyPath = InputBox(MyText, Title, Default)
If MyPath = "" Then
End
End If

' prevent any flickering
Application.ScreenUpdating = False

While Counter Letters
With Selection

.HomeKey Unit:=wdStory
.EndKey Unit:=wdLine, Extend:=wdExtend
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend

End With
sName = Selection
Docname = MyPath & "\" & MyName & "." & sName & "_" &
LTrim$(Str$(Counter))
& ".doc"

ActiveDocument.Sections.First.Range.Cut
Documents.Add
With Selection
.Paste
.HomeKey Unit:=wdStory
.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
.Delete
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Wend

' prevent any flickering
Application.ScreenUpdating = True
End Sub


Many Thanks





Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to export mail merge fields to excel Andrew Mailmerge 1 November 9th 06 03:55 AM
Using macro, mail merge, access [email protected] Mailmerge 5 December 14th 05 01:20 PM
Mail merge macro does not find database query katescotland Mailmerge 0 September 9th 05 09:17 AM
Mail Merge Macro Know your Word... Mailmerge 1 June 17th 05 10:43 AM
Mail merge and macro OliveX Mailmerge 0 May 18th 05 05:51 AM


All times are GMT +1. The time now is 09:12 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"