A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Mailmerge
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Advice for newbies VBA required mail merges



 
 
Thread Tools Display Modes
  #1  
Old May 16th, 2005, 06:21 PM
Parisa
external usenet poster
 
Posts: n/a
Default Advice for newbies VBA required mail merges

I've been doing a lot of mail merges that require special tweaking with
macros like taking a document and splitting & saving a document into separate
files with the added difficult of having the filename come from fields within
the document. I'm still working on that one.

Anyway, I'm not macro or VB proficient. So far I've borrowed code from this
newsgroup. Are there any sites or books that specialized in VBA mail merges
for newbies? I'm having a tough time understanding the code I'm borrow from
the experts. I need step by step instruction to begin with.
Thanks
  #2  
Old May 16th, 2005, 07:45 PM
Doug Robbins
external usenet poster
 
Posts: n/a
Default

See the article "What do I do with macros sent to me by other newsgroup
readers

to help me out?" at:

http://word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm


--
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
"Parisa" wrote in message
...
I've been doing a lot of mail merges that require special tweaking with
macros like taking a document and splitting & saving a document into
separate
files with the added difficult of having the filename come from fields
within
the document. I'm still working on that one.

Anyway, I'm not macro or VB proficient. So far I've borrowed code from
this
newsgroup. Are there any sites or books that specialized in VBA mail
merges
for newbies? I'm having a tough time understanding the code I'm borrow
from
the experts. I need step by step instruction to begin with.
Thanks



  #3  
Old May 16th, 2005, 09:36 PM
Graham Mayor
external usenet poster
 
Posts: n/a
Default

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

As for the code to split a merge using field information, there are a couple
of possibilities - one would be to insert an extra field (or combination of
fields to make a single 'word') that provides the (unique!) filename as the
first thing on the page of the merge document, then run the following
variation on Doug's splitter macro which uses that field or combination to
name the file then deletes it.

Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "D:\My Documents\Test\Merge\"
Docname = sPath & sName & LTrim$(Str$(Counter))
ActiveDocument.Sections.First.Range.Cut
Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub

You'll find alternative splitting code on my web site.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org





Parisa wrote:
I've been doing a lot of mail merges that require special tweaking
with macros like taking a document and splitting & saving a document
into separate files with the added difficult of having the filename
come from fields within the document. I'm still working on that one.

Anyway, I'm not macro or VB proficient. So far I've borrowed code
from this newsgroup. Are there any sites or books that specialized in
VBA mail merges for newbies? I'm having a tough time understanding
the code I'm borrow from the experts. I need step by step instruction
to begin with.
Thanks



  #4  
Old May 19th, 2005, 01:39 AM
Parisa
external usenet poster
 
Posts: n/a
Default

I'm an idiot. I finally figure it out. Thank You . I changed the code
slightly. I removed the index at the end. I have a space at the end but I'm
trying figure out how to remove the space. I'll figure it out yet.

I recorded the following macro.

With ActiveDocument
.TrackRevisions = True
.PrintRevisions = True
.ShowRevisions = True
End With
End Sub

I tried to incorporate this code into the code below. I added it between
ActiveDocument.Sections.First.Range.Cut and Documents.Add.

ActiveDocument.Sections.First.Range.Cut
ActiveDocument.TrackRevisions = True
ActiveDocument.PrintRevisions = True
ActiveDocument.ShowRevisions = True
Documents.Add

It turned on track changes but it didn't create each new document. What am I
doing wrong?


Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "C:\MERGELETTERS\"
Docname = sPath & sName
ActiveDocument.Sections.First.Range.Cut

Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub



"Graham Mayor" wrote:

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

As for the code to split a merge using field information, there are a couple
of possibilities - one would be to insert an extra field (or combination of
fields to make a single 'word') that provides the (unique!) filename as the
first thing on the page of the merge document, then run the following
variation on Doug's splitter macro which uses that field or combination to
name the file then deletes it.

Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "D:\My Documents\Test\Merge\"
Docname = sPath & sName & LTrim$(Str$(Counter))
ActiveDocument.Sections.First.Range.Cut
Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub

You'll find alternative splitting code on my web site.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org





Parisa wrote:
I've been doing a lot of mail merges that require special tweaking
with macros like taking a document and splitting & saving a document
into separate files with the added difficult of having the filename
come from fields within the document. I'm still working on that one.

Anyway, I'm not macro or VB proficient. So far I've borrowed code
from this newsgroup. Are there any sites or books that specialized in
VBA mail merges for newbies? I'm having a tough time understanding
the code I'm borrow from the experts. I need step by step instruction
to begin with.
Thanks




  #5  
Old May 19th, 2005, 09:28 PM
Parisa
external usenet poster
 
Posts: n/a
Default

I'm not sure if I should start a new thread or if this issue closed. Can
someone direct me please.

Thanks :0)

"Parisa" wrote:

I'm an idiot. I finally figure it out. Thank You . I changed the code
slightly. I removed the index at the end. I have a space at the end but I'm
trying figure out how to remove the space. I'll figure it out yet.

I recorded the following macro.

With ActiveDocument
.TrackRevisions = True
.PrintRevisions = True
.ShowRevisions = True
End With
End Sub

I tried to incorporate this code into the code below. I added it between
ActiveDocument.Sections.First.Range.Cut and Documents.Add.

ActiveDocument.Sections.First.Range.Cut
ActiveDocument.TrackRevisions = True
ActiveDocument.PrintRevisions = True
ActiveDocument.ShowRevisions = True
Documents.Add

It turned on track changes but it didn't create each new document. What am I
doing wrong?


Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "C:\MERGELETTERS\"
Docname = sPath & sName
ActiveDocument.Sections.First.Range.Cut

Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub



"Graham Mayor" wrote:

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

As for the code to split a merge using field information, there are a couple
of possibilities - one would be to insert an extra field (or combination of
fields to make a single 'word') that provides the (unique!) filename as the
first thing on the page of the merge document, then run the following
variation on Doug's splitter macro which uses that field or combination to
name the file then deletes it.

Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "D:\My Documents\Test\Merge\"
Docname = sPath & sName & LTrim$(Str$(Counter))
ActiveDocument.Sections.First.Range.Cut
Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub

You'll find alternative splitting code on my web site.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org





Parisa wrote:
I've been doing a lot of mail merges that require special tweaking
with macros like taking a document and splitting & saving a document
into separate files with the added difficult of having the filename
come from fields within the document. I'm still working on that one.

Anyway, I'm not macro or VB proficient. So far I've borrowed code
from this newsgroup. Are there any sites or books that specialized in
VBA mail merges for newbies? I'm having a tough time understanding
the code I'm borrow from the experts. I need step by step instruction
to begin with.
Thanks




  #6  
Old May 20th, 2005, 12:21 PM
Doug Robbins
external usenet poster
 
Posts: n/a
Default

Exactly what is it that you are trying to do? Where did the track changes
come into it?

--
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
"Parisa" wrote in message
...
I'm not sure if I should start a new thread or if this issue closed. Can
someone direct me please.

Thanks :0)

"Parisa" wrote:

I'm an idiot. I finally figure it out. Thank You . I changed the code
slightly. I removed the index at the end. I have a space at the end but
I'm
trying figure out how to remove the space. I'll figure it out yet.

I recorded the following macro.

With ActiveDocument
.TrackRevisions = True
.PrintRevisions = True
.ShowRevisions = True
End With
End Sub

I tried to incorporate this code into the code below. I added it between
ActiveDocument.Sections.First.Range.Cut and Documents.Add.

ActiveDocument.Sections.First.Range.Cut
ActiveDocument.TrackRevisions = True
ActiveDocument.PrintRevisions = True
ActiveDocument.ShowRevisions = True
Documents.Add

It turned on track changes but it didn't create each new document. What
am I
doing wrong?


Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "C:\MERGELETTERS\"
Docname = sPath & sName
ActiveDocument.Sections.First.Range.Cut

Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub



"Graham Mayor" wrote:

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

As for the code to split a merge using field information, there are a
couple
of possibilities - one would be to insert an extra field (or
combination of
fields to make a single 'word') that provides the (unique!) filename
as the
first thing on the page of the merge document, then run the following
variation on Doug's splitter macro which uses that field or combination
to
name the file then deletes it.

Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by
a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "D:\My Documents\Test\Merge\"
Docname = sPath & sName & LTrim$(Str$(Counter))
ActiveDocument.Sections.First.Range.Cut
Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub

You'll find alternative splitting code on my web site.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org





Parisa wrote:
I've been doing a lot of mail merges that require special tweaking
with macros like taking a document and splitting & saving a document
into separate files with the added difficult of having the filename
come from fields within the document. I'm still working on that one.

Anyway, I'm not macro or VB proficient. So far I've borrowed code
from this newsgroup. Are there any sites or books that specialized in
VBA mail merges for newbies? I'm having a tough time understanding
the code I'm borrow from the experts. I need step by step instruction
to begin with.
Thanks





  #7  
Old May 20th, 2005, 01:15 PM
Parisa
external usenet poster
 
Posts: n/a
Default

When the user opens the file(s) I want to have the track changes feature
already enabled. I realize most users know how to enable it but my "users"
(attorneys) don't have a clue. Believe me.
Since the below code works perfectly. I wanted add additional code to enable
the track changes (revisions) feature before the file is saved.
I was trying to add it myself but it just doesn't work. Please help.


Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "C:\MERGELETTERS\"
Docname = sPath & sName
ActiveDocument.Sections.First.Range.Cut

Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub




"Doug Robbins" wrote:

Exactly what is it that you are trying to do? Where did the track changes
come into it?

--
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
"Parisa" wrote in message
...
I'm not sure if I should start a new thread or if this issue closed. Can
someone direct me please.

Thanks :0)

"Parisa" wrote:

I'm an idiot. I finally figure it out. Thank You . I changed the code
slightly. I removed the index at the end. I have a space at the end but
I'm
trying figure out how to remove the space. I'll figure it out yet.

I recorded the following macro.

With ActiveDocument
.TrackRevisions = True
.PrintRevisions = True
.ShowRevisions = True
End With
End Sub

I tried to incorporate this code into the code below. I added it between
ActiveDocument.Sections.First.Range.Cut and Documents.Add.

ActiveDocument.Sections.First.Range.Cut
ActiveDocument.TrackRevisions = True
ActiveDocument.PrintRevisions = True
ActiveDocument.ShowRevisions = True
Documents.Add

It turned on track changes but it didn't create each new document. What
am I
doing wrong?


Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "C:\MERGELETTERS\"
Docname = sPath & sName
ActiveDocument.Sections.First.Range.Cut

Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub



"Graham Mayor" wrote:

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

As for the code to split a merge using field information, there are a
couple
of possibilities - one would be to insert an extra field (or
combination of
fields to make a single 'word') that provides the (unique!) filename
as the
first thing on the page of the merge document, then run the following
variation on Doug's splitter macro which uses that field or combination
to
name the file then deletes it.

Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by
a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "D:\My Documents\Test\Merge\"
Docname = sPath & sName & LTrim$(Str$(Counter))
ActiveDocument.Sections.First.Range.Cut
Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub

You'll find alternative splitting code on my web site.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org





Parisa wrote:
I've been doing a lot of mail merges that require special tweaking
with macros like taking a document and splitting & saving a document
into separate files with the added difficult of having the filename
come from fields within the document. I'm still working on that one.

Anyway, I'm not macro or VB proficient. So far I've borrowed code
from this newsgroup. Are there any sites or books that specialized in
VBA mail merges for newbies? I'm having a tough time understanding
the code I'm borrow from the experts. I need step by step instruction
to begin with.
Thanks






  #8  
Old May 21st, 2005, 06:48 AM
Doug Robbins
external usenet poster
 
Posts: n/a
Default

Try the following modification

Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "C:\MERGELETTERS\"
Docname = sPath & sName
ActiveDocument.Sections.First.Range.Cut

Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
With ActiveDocument
.TrackRevisions = True
.PrintRevisions = True
.ShowRevisions = True
.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
End With
ActiveDocument ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub

As you can tell from the date, that is a really old macro and this is the
way that I would do the basis splitting of the document today:

' Macro created by Doug Robbins to save each letter created by a mailmerge
as a separate file.

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
Letter.End=Letter.End-1
Set Target = Documents.Add
Target.Range=Letter
Target.SaveAs FileName:="Letter" & i
Target.Close
Next i


--
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
"Parisa" wrote in message
...
When the user opens the file(s) I want to have the track changes feature
already enabled. I realize most users know how to enable it but my "users"
(attorneys) don't have a clue. Believe me.
Since the below code works perfectly. I wanted add additional code to
enable
the track changes (revisions) feature before the file is saved.
I was trying to add it myself but it just doesn't work. Please help.


Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "C:\MERGELETTERS\"
Docname = sPath & sName
ActiveDocument.Sections.First.Range.Cut

Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub




"Doug Robbins" wrote:

Exactly what is it that you are trying to do? Where did the track
changes
come into it?

--
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
"Parisa" wrote in message
...
I'm not sure if I should start a new thread or if this issue closed.
Can
someone direct me please.

Thanks :0)

"Parisa" wrote:

I'm an idiot. I finally figure it out. Thank You . I changed the code
slightly. I removed the index at the end. I have a space at the end
but
I'm
trying figure out how to remove the space. I'll figure it out yet.

I recorded the following macro.

With ActiveDocument
.TrackRevisions = True
.PrintRevisions = True
.ShowRevisions = True
End With
End Sub

I tried to incorporate this code into the code below. I added it
between
ActiveDocument.Sections.First.Range.Cut and Documents.Add.

ActiveDocument.Sections.First.Range.Cut
ActiveDocument.TrackRevisions = True
ActiveDocument.PrintRevisions = True
ActiveDocument.ShowRevisions = True
Documents.Add

It turned on track changes but it didn't create each new document.
What
am I
doing wrong?


Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created
by a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "C:\MERGELETTERS\"
Docname = sPath & sName
ActiveDocument.Sections.First.Range.Cut

Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub



"Graham Mayor" wrote:

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

As for the code to split a merge using field information, there are
a
couple
of possibilities - one would be to insert an extra field (or
combination of
fields to make a single 'word') that provides the (unique!)
filename
as the
first thing on the page of the merge document, then run the
following
variation on Doug's splitter macro which uses that field or
combination
to
name the file then deletes it.

Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created
by
a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "D:\My Documents\Test\Merge\"
Docname = sPath & sName & LTrim$(Str$(Counter))
ActiveDocument.Sections.First.Range.Cut
Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub

You'll find alternative splitting code on my web site.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org





Parisa wrote:
I've been doing a lot of mail merges that require special tweaking
with macros like taking a document and splitting & saving a
document
into separate files with the added difficult of having the
filename
come from fields within the document. I'm still working on that
one.

Anyway, I'm not macro or VB proficient. So far I've borrowed code
from this newsgroup. Are there any sites or books that specialized
in
VBA mail merges for newbies? I'm having a tough time understanding
the code I'm borrow from the experts. I need step by step
instruction
to begin with.
Thanks








  #9  
Old May 23rd, 2005, 08:32 PM
Parisa
external usenet poster
 
Posts: n/a
Default

I did try using the Sub SplitMergeLetter() with te track changes on but it
doesn't work. I get an error message. It says Compile error. Expected
function or variable.

It highlighted this statement " ActiveDocument ActiveWindow.Close"

"Doug Robbins" wrote:

Try the following modification

Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "C:\MERGELETTERS\"
Docname = sPath & sName
ActiveDocument.Sections.First.Range.Cut

Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
With ActiveDocument
.TrackRevisions = True
.PrintRevisions = True
.ShowRevisions = True
.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
End With
ActiveDocument ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub

As you can tell from the date, that is a really old macro and this is the
way that I would do the basis splitting of the document today:

' Macro created by Doug Robbins to save each letter created by a mailmerge
as a separate file.

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
Letter.End=Letter.End-1
Set Target = Documents.Add
Target.Range=Letter
Target.SaveAs FileName:="Letter" & i
Target.Close
Next i


--
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
"Parisa" wrote in message
...
When the user opens the file(s) I want to have the track changes feature
already enabled. I realize most users know how to enable it but my "users"
(attorneys) don't have a clue. Believe me.
Since the below code works perfectly. I wanted add additional code to
enable
the track changes (revisions) feature before the file is saved.
I was trying to add it myself but it just doesn't work. Please help.


Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "C:\MERGELETTERS\"
Docname = sPath & sName
ActiveDocument.Sections.First.Range.Cut

Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub




"Doug Robbins" wrote:

Exactly what is it that you are trying to do? Where did the track
changes
come into it?

--
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
"Parisa" wrote in message
...
I'm not sure if I should start a new thread or if this issue closed.
Can
someone direct me please.

Thanks :0)

"Parisa" wrote:

I'm an idiot. I finally figure it out. Thank You . I changed the code
slightly. I removed the index at the end. I have a space at the end
but
I'm
trying figure out how to remove the space. I'll figure it out yet.

I recorded the following macro.

With ActiveDocument
.TrackRevisions = True
.PrintRevisions = True
.ShowRevisions = True
End With
End Sub

I tried to incorporate this code into the code below. I added it
between
ActiveDocument.Sections.First.Range.Cut and Documents.Add.

ActiveDocument.Sections.First.Range.Cut
ActiveDocument.TrackRevisions = True
ActiveDocument.PrintRevisions = True
ActiveDocument.ShowRevisions = True
Documents.Add

It turned on track changes but it didn't create each new document.
What
am I
doing wrong?


Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created
by a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "C:\MERGELETTERS\"
Docname = sPath & sName
ActiveDocument.Sections.First.Range.Cut

Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub



"Graham Mayor" wrote:

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

As for the code to split a merge using field information, there are
a
couple
of possibilities - one would be to insert an extra field (or
combination of
fields to make a single 'word') that provides the (unique!)
filename
as the
first thing on the page of the merge document, then run the
following
variation on Doug's splitter macro which uses that field or
combination
to
name the file then deletes it.

Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created
by
a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "D:\My Documents\Test\Merge\"
Docname = sPath & sName & LTrim$(Str$(Counter))
ActiveDocument.Sections.First.Range.Cut
Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub

You'll find alternative splitting code on my web site.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org





Parisa wrote:
I've been doing a lot of mail merges that require special tweaking
with macros like taking a document and splitting & saving a
document
into separate files with the added difficult of having the
filename
come from fields within the document. I'm still working on that
one.

Anyway, I'm not macro or VB proficient. So far I've borrowed code
from this newsgroup. Are there any sites or books that specialized
in
VBA mail merges for newbies? I'm having a tough time understanding
the code I'm borrow from the experts. I need step by step
instruction
to begin with.
Thanks









  #10  
Old May 24th, 2005, 07:10 AM
Doug Robbins
external usenet poster
 
Posts: n/a
Default

Seems like something got deleted, instead of

ActiveDocument ActiveWindow.Close

it should have been

ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close


--
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
"Parisa" wrote in message
...
I did try using the Sub SplitMergeLetter() with te track changes on but it
doesn't work. I get an error message. It says Compile error. Expected
function or variable.

It highlighted this statement " ActiveDocument ActiveWindow.Close"

"Doug Robbins" wrote:

Try the following modification

Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "C:\MERGELETTERS\"
Docname = sPath & sName
ActiveDocument.Sections.First.Range.Cut

Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
With ActiveDocument
.TrackRevisions = True
.PrintRevisions = True
.ShowRevisions = True
.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
End With
ActiveDocument ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub

As you can tell from the date, that is a really old macro and this is the
way that I would do the basis splitting of the document today:

' Macro created by Doug Robbins to save each letter created by a
mailmerge
as a separate file.

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
Letter.End=Letter.End-1
Set Target = Documents.Add
Target.Range=Letter
Target.SaveAs FileName:="Letter" & i
Target.Close
Next i


--
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
"Parisa" wrote in message
...
When the user opens the file(s) I want to have the track changes
feature
already enabled. I realize most users know how to enable it but my
"users"
(attorneys) don't have a clue. Believe me.
Since the below code works perfectly. I wanted add additional code to
enable
the track changes (revisions) feature before the file is saved.
I was trying to add it myself but it just doesn't work. Please help.


Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by
a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "C:\MERGELETTERS\"
Docname = sPath & sName
ActiveDocument.Sections.First.Range.Cut

Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub




"Doug Robbins" wrote:

Exactly what is it that you are trying to do? Where did the track
changes
come into it?

--
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
"Parisa" wrote in message
...
I'm not sure if I should start a new thread or if this issue closed.
Can
someone direct me please.

Thanks :0)

"Parisa" wrote:

I'm an idiot. I finally figure it out. Thank You . I changed the
code
slightly. I removed the index at the end. I have a space at the end
but
I'm
trying figure out how to remove the space. I'll figure it out yet.

I recorded the following macro.

With ActiveDocument
.TrackRevisions = True
.PrintRevisions = True
.ShowRevisions = True
End With
End Sub

I tried to incorporate this code into the code below. I added it
between
ActiveDocument.Sections.First.Range.Cut and Documents.Add.

ActiveDocument.Sections.First.Range.Cut
ActiveDocument.TrackRevisions = True
ActiveDocument.PrintRevisions = True
ActiveDocument.ShowRevisions = True
Documents.Add

It turned on track changes but it didn't create each new document.
What
am I
doing wrong?


Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter
created
by a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "C:\MERGELETTERS\"
Docname = sPath & sName
ActiveDocument.Sections.First.Range.Cut

Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub



"Graham Mayor" wrote:

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

As for the code to split a merge using field information, there
are
a
couple
of possibilities - one would be to insert an extra field (or
combination of
fields to make a single 'word') that provides the (unique!)
filename
as the
first thing on the page of the merge document, then run the
following
variation on Doug's splitter macro which uses that field or
combination
to
name the file then deletes it.

Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter
created
by
a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "D:\My Documents\Test\Merge\"
Docname = sPath & sName & LTrim$(Str$(Counter))
ActiveDocument.Sections.First.Range.Cut
Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub

You'll find alternative splitting code on my web site.

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org





Parisa wrote:
I've been doing a lot of mail merges that require special
tweaking
with macros like taking a document and splitting & saving a
document
into separate files with the added difficult of having the
filename
come from fields within the document. I'm still working on that
one.

Anyway, I'm not macro or VB proficient. So far I've borrowed
code
from this newsgroup. Are there any sites or books that
specialized
in
VBA mail merges for newbies? I'm having a tough time
understanding
the code I'm borrow from the experts. I need step by step
instruction
to begin with.
Thanks











 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Not able to configure yahoo mail in outlook Puneet General Discussion 5 January 24th, 2005 02:33 PM
OE 6 Freezes when opening mail / creating mail tina SPEILBERG Outlook Express 18 August 30th, 2004 05:23 PM
OE6 and AVG (Free Edition) Aquarius Outlook Express 10 August 16th, 2004 09:54 PM
URGENT: Mailing rule problems of filing in outlook express and hard copy file systems in real case Teres Outlook Express 7 August 14th, 2004 01:55 AM
Bcc John General Discussion 10 July 8th, 2004 02:41 PM


All times are GMT +1. The time now is 06:39 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.