Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
 
Posts: n/a
Default Mail Merge & Find/Replace

Hi,

I came accross the gmayor macro to split a mail merge file into
serparate files as the merge is occuring and this fixed a big problem I
was running into. What I'm trying to do now is perform a find/replace
on each document as it's created. I would prefer to just add some code
to the macro which gmayor wrote but me being a bit new at this I'm not
sure where to place the code within his. Any help would be greatly
appreciated. The replace is to change a set character into a line break
incase anyone is wondering. The code used in gmayor's macro is
available at http://www.gmayor.com/individual_merge_letters.htm near
the bottom of the page. Thanks in advance.

  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
what4893
 
Posts: n/a
Default Mail Merge & Find/Replace

Sorry for not listing what I'm replacing. I have an Access database
that is tied to some ASP .NET pages I have written. Each month I need
to create letters with some of the data that was entered from the
previous month. The problem is that I need the data split into nice
even columns and the data is coming out in one long stream. So, what I
did is where ever I need a line break I have programmed my ASP .NET
page to output CR then once in Word I just do a find and replace to
convert all of the CR tags to ^l which is the new line character
recognized by Word. Unfortunately if I just use ^l in my ASP output
code Word considers it as text and doesn't interpret the character.

As you mentioned it would be much easier to execute a single long mail
merge and then run the find and replace. This is true except that I
need all the letters broken up into separate files so I can save them
to different locations AND if the letters aren't separated the pages
numbers inserted by Word will say 1 of 76 or however many letters are
created in the one long mail merge. The reason I need the dynamic page
numbers is that the letters are of differing lengths each month
depending on how much information is inputed. Thanks for your quick
response.

  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP
 
Posts: n/a
Default Mail Merge & Find/Replace

If the page numbering is really the thing that is controlling this, format
the page numbering in the mailmerge main document so that it starts at one,
rather than continuing from the previous section (you may already have that)
AND instead of using a { NUMPAGE } field to get the total number of pages in
each letter, use a { SECTIONPAGES } field. Then your individual letters
will be numbered correctly.

However, adding the following code

With NewDoc
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="CR", Replacewith:="^l",
MatchWildcards:=False, Wrap:=wdFindContinue, _ Forward:=True) = True
Loop
End With
End With

before the commands

NewDoc.Range.Fields.Update
NewDoc.SaveAs FldrPath & fnames(i)

in the

Private Sub app_MailMergeAfterMerge(ByVal Doc As Document, ByVal DocResult
As Document)

event in the Addin, should (I haven't tested it) do the replacement on each
individual document. I would suggest however that you try and avoid having
to do 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

"what4893" wrote in message
ups.com...
Sorry for not listing what I'm replacing. I have an Access database
that is tied to some ASP .NET pages I have written. Each month I need
to create letters with some of the data that was entered from the
previous month. The problem is that I need the data split into nice
even columns and the data is coming out in one long stream. So, what I
did is where ever I need a line break I have programmed my ASP .NET
page to output CR then once in Word I just do a find and replace to
convert all of the CR tags to ^l which is the new line character
recognized by Word. Unfortunately if I just use ^l in my ASP output
code Word considers it as text and doesn't interpret the character.

As you mentioned it would be much easier to execute a single long mail
merge and then run the find and replace. This is true except that I
need all the letters broken up into separate files so I can save them
to different locations AND if the letters aren't separated the pages
numbers inserted by Word will say 1 of 76 or however many letters are
created in the one long mail merge. The reason I need the dynamic page
numbers is that the letters are of differing lengths each month
depending on how much information is inputed. Thanks for your quick
response.



  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
what4893
 
Posts: n/a
Default Mail Merge & Find/Replace

Thanks for your detailed response. I went ahead and placed the code you
recommended into the MailMerge macro written by GMayor. The mail merge
still works perfectly but it doesn't actually perform the find and
replace. Any ideas? The reason I'm going forward with this approach is
because ultimately I need the letters in separate files. The page
numbers were just a bonus in splitting the files and I thank you for
letting me know about the section page numbers. I didn't know that and
that may come in handy in the future.

No errors occur during the merge, the files are created and when I go
into the files they all still have my CR's in them. I didn't think it
crucial before, and I appologize if this makes a difference, the CR
tags all appear in a table. That is why I'm trying to get them to
become line breaks, so that the columns each have one line in them. For
a little visual of my situation see below:

|--------------|-----------------|
|ABCCRABC |123CR123CR123|
|CRABCCR |CR123CR123 |
|--------------|-----------------|

The mail merge puts that data into the table cells and then I'm
replacing the CR tags with ^l (new lines). Thanks again for your help
on this project.



  #6   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP
 
Posts: n/a
Default Mail Merge & Find/Replace

Eactly which macro on Graham's site are you using?

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

"what4893" wrote in message
oups.com...
Thanks for your detailed response. I went ahead and placed the code you
recommended into the MailMerge macro written by GMayor. The mail merge
still works perfectly but it doesn't actually perform the find and
replace. Any ideas? The reason I'm going forward with this approach is
because ultimately I need the letters in separate files. The page
numbers were just a bonus in splitting the files and I thank you for
letting me know about the section page numbers. I didn't know that and
that may come in handy in the future.

No errors occur during the merge, the files are created and when I go
into the files they all still have my CR's in them. I didn't think it
crucial before, and I appologize if this makes a difference, the CR
tags all appear in a table. That is why I'm trying to get them to
become line breaks, so that the columns each have one line in them. For
a little visual of my situation see below:

|--------------|-----------------|
|ABCCRABC |123CR123CR123|
|CRABCCR |CR123CR123 |
|--------------|-----------------|

The mail merge puts that data into the table cells and then I'm
replacing the CR tags with ^l (new lines). Thanks again for your help
on this project.



  #7   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Graham Mayor
 
Posts: n/a
Default Mail Merge & Find/Replace

Doug's additional code is meant to go in his add-in linked from the same
plage and not the original macro. The add-in is a much more elegant solution
where it can be used than the original macro (also based on Doug's code).

--

Graham Mayor - Word MVP

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


what4893 wrote:
Thanks for your detailed response. I went ahead and placed the code
you recommended into the MailMerge macro written by GMayor. The mail
merge still works perfectly but it doesn't actually perform the find
and replace. Any ideas? The reason I'm going forward with this
approach is because ultimately I need the letters in separate files.
The page numbers were just a bonus in splitting the files and I thank
you for letting me know about the section page numbers. I didn't know
that and that may come in handy in the future.

No errors occur during the merge, the files are created and when I go
into the files they all still have my CR's in them. I didn't think
it crucial before, and I appologize if this makes a difference, the
CR tags all appear in a table. That is why I'm trying to get them to
become line breaks, so that the columns each have one line in them.
For a little visual of my situation see below:

--------------|-----------------|
ABCCRABC |123CR123CR123|
CRABCCR |CR123CR123 |
--------------|-----------------|


The mail merge puts that data into the table cells and then I'm
replacing the CR tags with ^l (new lines). Thanks again for your
help on this project.



  #8   Report Post  
Posted to microsoft.public.word.mailmerge.fields
what4893
 
Posts: n/a
Default Mail Merge & Find/Replace

I'm using the Word Add-In Template. It is a .dot file with the macro
for the mail merge built in. The macro intercepts the mail merge call
from Word and uses his code to perform the merge. Thanks again for your
help.

  #9   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP
 
Posts: n/a
Default Mail Merge & Find/Replace

With the following insertion into the code in the Private Sub
app_MailMergeAfterMerge(ByVal Doc As Document, ByVal DocResult
As Document) event,

NewDoc.Range.Fields.Update
'Begin insert
With NewDoc
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="CR", Replacewith:="^l",
MatchWildcards:=False, Wrap:=wdFindContinue, Forward:=True) = True
Loop
End With
End With
'End insert
NewDoc.SaveAs FldrPath & fnames(i)

When I execute a mailmerge main document containing a table with each cell
containing:

The quick brown fox jumps over the lazy dog.CRThe quick brown fox jumps
over the lazy dog.CRThe quick brown fox jumps over the lazy dog.CRThe
quick brown fox jumps over the lazy dog.CRThe quick brown fox jumps over
the lazy dog.

to a new document, and make use of the add-in, the contents of the each cell
in the resulting documents created by the add-in become:

The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.

So it certainly works.
--
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

"what4893" wrote in message
oups.com...
I'm using the Word Add-In Template. It is a .dot file with the macro
for the mail merge built in. The macro intercepts the mail merge call
from Word and uses his code to perform the merge. Thanks again for your
help.



  #10   Report Post  
Posted to microsoft.public.word.mailmerge.fields
what4893
 
Posts: n/a
Default Mail Merge & Find/Replace

I tried pasting the code again, I deleted the Add-In file and used a
new copy. Everything I could think of and ultimately it looks like I'm
having trouble with Word or VB6. I thank you for your support on the
issue. If you happen to have a copy of the Add-In file with the code
pasted into it perhaps if you could email that to me I could try that
but everything I have tried hasn't worked. Thanks again for all your
support.



  #11   Report Post  
Posted to microsoft.public.word.mailmerge.fields
what4893
 
Posts: n/a
Default Mail Merge & Find/Replace

Thank you sooooo much Doug. You are truly a Microsoft Word MVP Geneous.

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
NO CODE - mail merge to Outlook with attachment with CC BrianH Mailmerge 1 February 10th 10 02:53 PM
Adding a field to an Off 97 mail merge using Office Pro 2003 TomC Mailmerge 1 January 5th 06 08:00 AM
Mail Merge Losing Data Scott May Mailmerge 1 November 1st 05 11:03 PM
Mail Merge - Parameter prompts twice... TL Mailmerge 6 June 17th 05 02:58 PM
mail merge with attachments AS Mailmerge 5 April 9th 05 09:49 AM


All times are GMT +1. The time now is 09:42 AM.

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"