Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Drew Drew is offline
external usenet poster
 
Posts: 4
Default Replacing text with Merge Fields in Word

I am attempting to convert a plain text document that contains certain
variables as delimited by the "@" or other user specified delimiters
and I can't seem to get the merge fields to position themselves in the
proper location. What currently happens is that the variables are
successfully removed, but the merge fields are all placed at the end of
the document. Also, any merge fields that have more than one word in
the field name is truncated to only the first word of the field's name.
The code that I am using is below:

With objWord.Content.find
rsVariableDefinitions.MoveFirst
Do Until rsVariableDefinitions.EOF 'loop
through variable definition table and replace text with their merge
fields
.Execute strDelimiter &
rsVariableDefinitions!Variable & strDelimiter, , True, , , , True, , ,
"", True 'Delete the variable placeholder
If .Found Then
Let strField =
rsVariableDefinitions("Field")
objWord.MailMerge.Fields.Add
oSel.Range, strField
End If
rsVariableDefinitions.MoveNext
Loop
End With

Can any one please help!

Thanks, Drew

  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Replacing text with Merge Fields in Word

It would be easier to answer this if we knew anything about the
rsVariableDefinitions object (which I think is "proprietary"), but:
a. What is actually being returned by the statement

Let strField = rsVariableDefinitions("Field") ?
b. is anything setting oSel to be at the location you just found (i.e. the
Selection object might be at the correct location, but probably not oSel)

Peter Jamieson

"Drew" wrote in message
ups.com...
I am attempting to convert a plain text document that contains certain
variables as delimited by the "@" or other user specified delimiters
and I can't seem to get the merge fields to position themselves in the
proper location. What currently happens is that the variables are
successfully removed, but the merge fields are all placed at the end of
the document. Also, any merge fields that have more than one word in
the field name is truncated to only the first word of the field's name.
The code that I am using is below:

With objWord.Content.find
rsVariableDefinitions.MoveFirst
Do Until rsVariableDefinitions.EOF 'loop
through variable definition table and replace text with their merge
fields
.Execute strDelimiter &
rsVariableDefinitions!Variable & strDelimiter, , True, , , , True, , ,
"", True 'Delete the variable placeholder
If .Found Then
Let strField =
rsVariableDefinitions("Field")
objWord.MailMerge.Fields.Add
oSel.Range, strField
End If
rsVariableDefinitions.MoveNext
Loop
End With

Can any one please help!

Thanks, Drew



  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Drew Drew is offline
external usenet poster
 
Posts: 4
Default Replacing text with Merge Fields in Word

Hi Peter,

Actually the rsVariableDefinitions object is simply a recordset that
maps the variable name to the merge field to be used for that name.

What you say about selection object is exactly correct; my problem is
that I don't know how to set the oSel to be at the location I just
found. How do I do that??

thanks, Drew

Peter Jamieson wrote:
It would be easier to answer this if we knew anything about the
rsVariableDefinitions object (which I think is "proprietary"), but:
a. What is actually being returned by the statement

Let strField = rsVariableDefinitions("Field") ?
b. is anything setting oSel to be at the location you just found (i.e. the
Selection object might be at the correct location, but probably not oSel)

Peter Jamieson

"Drew" wrote in message
ups.com...
I am attempting to convert a plain text document that contains certain
variables as delimited by the "@" or other user specified delimiters
and I can't seem to get the merge fields to position themselves in the
proper location. What currently happens is that the variables are
successfully removed, but the merge fields are all placed at the end of
the document. Also, any merge fields that have more than one word in
the field name is truncated to only the first word of the field's name.
The code that I am using is below:

With objWord.Content.find
rsVariableDefinitions.MoveFirst
Do Until rsVariableDefinitions.EOF 'loop
through variable definition table and replace text with their merge
fields
.Execute strDelimiter &
rsVariableDefinitions!Variable & strDelimiter, , True, , , , True, , ,
"", True 'Delete the variable placeholder
If .Found Then
Let strField =
rsVariableDefinitions("Field")
objWord.MailMerge.Fields.Add
oSel.Range, strField
End If
rsVariableDefinitions.MoveNext
Loop
End With

Can any one please help!

Thanks, Drew


  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Replacing text with Merge Fields in Word

Suggestons off the top of my head...

just use "Selection" instead of "oSel" (but qulaify it if necessary if the
code is e.g. being run from Excel rather than WOrd

or try

Set oSel = Selection

before referencing oSel.

Peter Jamieson

"Drew" wrote in message
ups.com...
Hi Peter,

Actually the rsVariableDefinitions object is simply a recordset that
maps the variable name to the merge field to be used for that name.

What you say about selection object is exactly correct; my problem is
that I don't know how to set the oSel to be at the location I just
found. How do I do that??

thanks, Drew

Peter Jamieson wrote:
It would be easier to answer this if we knew anything about the
rsVariableDefinitions object (which I think is "proprietary"), but:
a. What is actually being returned by the statement

Let strField = rsVariableDefinitions("Field") ?
b. is anything setting oSel to be at the location you just found (i.e.
the
Selection object might be at the correct location, but probably not oSel)

Peter Jamieson

"Drew" wrote in message
ups.com...
I am attempting to convert a plain text document that contains certain
variables as delimited by the "@" or other user specified delimiters
and I can't seem to get the merge fields to position themselves in the
proper location. What currently happens is that the variables are
successfully removed, but the merge fields are all placed at the end of
the document. Also, any merge fields that have more than one word in
the field name is truncated to only the first word of the field's name.
The code that I am using is below:

With objWord.Content.find
rsVariableDefinitions.MoveFirst
Do Until rsVariableDefinitions.EOF 'loop
through variable definition table and replace text with their merge
fields
.Execute strDelimiter &
rsVariableDefinitions!Variable & strDelimiter, , True, , , , True, , ,
"", True 'Delete the variable placeholder
If .Found Then
Let strField =
rsVariableDefinitions("Field")
objWord.MailMerge.Fields.Add
oSel.Range, strField
End If
rsVariableDefinitions.MoveNext
Loop
End With

Can any one please help!

Thanks, Drew




  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Drew Drew is offline
external usenet poster
 
Posts: 4
Default Replacing text with Merge Fields in Word

I tried both methods and each time Access returned an error: 'Object
is deleted.' So I used Selection.range and this did not return an
error, but the merge fields are still placed at the end of the
document. Is there a way to return the character positions of each of
the variables in the document so that I could implicitly instruct
Access to place the merge fields at those locations?

Peter Jamieson wrote:
Suggestons off the top of my head...

just use "Selection" instead of "oSel" (but qulaify it if necessary if the
code is e.g. being run from Excel rather than WOrd

or try

Set oSel = Selection

before referencing oSel.

Peter Jamieson

"Drew" wrote in message
ups.com...
Hi Peter,

Actually the rsVariableDefinitions object is simply a recordset that
maps the variable name to the merge field to be used for that name.

What you say about selection object is exactly correct; my problem is
that I don't know how to set the oSel to be at the location I just
found. How do I do that??

thanks, Drew

Peter Jamieson wrote:
It would be easier to answer this if we knew anything about the
rsVariableDefinitions object (which I think is "proprietary"), but:
a. What is actually being returned by the statement

Let strField = rsVariableDefinitions("Field") ?
b. is anything setting oSel to be at the location you just found (i.e.
the
Selection object might be at the correct location, but probably not oSel)

Peter Jamieson

"Drew" wrote in message
ups.com...
I am attempting to convert a plain text document that contains certain
variables as delimited by the "@" or other user specified delimiters
and I can't seem to get the merge fields to position themselves in the
proper location. What currently happens is that the variables are
successfully removed, but the merge fields are all placed at the end of
the document. Also, any merge fields that have more than one word in
the field name is truncated to only the first word of the field's name.
The code that I am using is below:

With objWord.Content.find
rsVariableDefinitions.MoveFirst
Do Until rsVariableDefinitions.EOF 'loop
through variable definition table and replace text with their merge
fields
.Execute strDelimiter &
rsVariableDefinitions!Variable & strDelimiter, , True, , , , True, , ,
"", True 'Delete the variable placeholder
If .Found Then
Let strField =
rsVariableDefinitions("Field")
objWord.MailMerge.Fields.Add
oSel.Range, strField
End If
rsVariableDefinitions.MoveNext
Loop
End With

Can any one please help!

Thanks, Drew





  #6   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Replacing text with Merge Fields in Word

Ah you're working in Access :-)

But in any case, now I've had a proper look I don't think the existing
approach will take you where you want to go.

I would start with something more like the following:

Dim objWordApp As Word.Application
'Dim rngFound As Word.Range
' If you already have a reference to the Word Application, just use that
' instead of setting up this new one
Set objWordApp = ActiveDocument.Application
rsVariableDefinitions.MoveFirst
Do Until rsVariableDefinitions.EOF
objWordApp.Selection.HomeKey wdStory
objWordApp.Selection.Find.ClearFormatting
With objWordApp.Selection.Find
Do While .Execute( _
FindText:=strDelimiter & rsVariableDefinitions!Variable &
strDelimiter, _
Wrap:=wdFindContinue, _
Forward:=True) = True
'Set rngFound = Selection.Range
ActiveDocument.Fields.Add _
Range:=objWordApp.Selection.Range, _
Type:=wdFieldMergeField, _
Text:=rsVariableDefinitions("Field")
Loop
End With
rsVariableDefinitions.MoveNext
Loop

Some of that stuff may be surplus to requirements but I think it's closer to
the mark.

Peter Jamieson

"Drew" wrote in message
ups.com...
I tried both methods and each time Access returned an error: 'Object
is deleted.' So I used Selection.range and this did not return an
error, but the merge fields are still placed at the end of the
document. Is there a way to return the character positions of each of
the variables in the document so that I could implicitly instruct
Access to place the merge fields at those locations?

Peter Jamieson wrote:
Suggestons off the top of my head...

just use "Selection" instead of "oSel" (but qulaify it if necessary if
the
code is e.g. being run from Excel rather than WOrd

or try

Set oSel = Selection

before referencing oSel.

Peter Jamieson

"Drew" wrote in message
ups.com...
Hi Peter,

Actually the rsVariableDefinitions object is simply a recordset that
maps the variable name to the merge field to be used for that name.

What you say about selection object is exactly correct; my problem is
that I don't know how to set the oSel to be at the location I just
found. How do I do that??

thanks, Drew

Peter Jamieson wrote:
It would be easier to answer this if we knew anything about the
rsVariableDefinitions object (which I think is "proprietary"), but:
a. What is actually being returned by the statement

Let strField = rsVariableDefinitions("Field") ?
b. is anything setting oSel to be at the location you just found
(i.e.
the
Selection object might be at the correct location, but probably not
oSel)

Peter Jamieson

"Drew" wrote in message
ups.com...
I am attempting to convert a plain text document that contains
certain
variables as delimited by the "@" or other user specified delimiters
and I can't seem to get the merge fields to position themselves in
the
proper location. What currently happens is that the variables are
successfully removed, but the merge fields are all placed at the end
of
the document. Also, any merge fields that have more than one word
in
the field name is truncated to only the first word of the field's
name.
The code that I am using is below:

With objWord.Content.find
rsVariableDefinitions.MoveFirst
Do Until rsVariableDefinitions.EOF 'loop
through variable definition table and replace text with their merge
fields
.Execute strDelimiter &
rsVariableDefinitions!Variable & strDelimiter, , True, , , , True, ,
,
"", True 'Delete the variable placeholder
If .Found Then
Let strField =
rsVariableDefinitions("Field")
objWord.MailMerge.Fields.Add
oSel.Range, strField
End If
rsVariableDefinitions.MoveNext
Loop
End With

Can any one please help!

Thanks, Drew





  #7   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Drew Drew is offline
external usenet poster
 
Posts: 4
Default Replacing text with Merge Fields in Word

Thank you, thank you, thank you! That's exactly what i needed. After
so many hours of frustration it's great to finally see this thing work!

Drew

Peter Jamieson wrote:
Ah you're working in Access :-)

But in any case, now I've had a proper look I don't think the existing
approach will take you where you want to go.

I would start with something more like the following:

Dim objWordApp As Word.Application
'Dim rngFound As Word.Range
' If you already have a reference to the Word Application, just use that
' instead of setting up this new one
Set objWordApp = ActiveDocument.Application
rsVariableDefinitions.MoveFirst
Do Until rsVariableDefinitions.EOF
objWordApp.Selection.HomeKey wdStory
objWordApp.Selection.Find.ClearFormatting
With objWordApp.Selection.Find
Do While .Execute( _
FindText:=strDelimiter & rsVariableDefinitions!Variable &
strDelimiter, _
Wrap:=wdFindContinue, _
Forward:=True) = True
'Set rngFound = Selection.Range
ActiveDocument.Fields.Add _
Range:=objWordApp.Selection.Range, _
Type:=wdFieldMergeField, _
Text:=rsVariableDefinitions("Field")
Loop
End With
rsVariableDefinitions.MoveNext
Loop

Some of that stuff may be surplus to requirements but I think it's closer to
the mark.

Peter Jamieson

"Drew" wrote in message
ups.com...
I tried both methods and each time Access returned an error: 'Object
is deleted.' So I used Selection.range and this did not return an
error, but the merge fields are still placed at the end of the
document. Is there a way to return the character positions of each of
the variables in the document so that I could implicitly instruct
Access to place the merge fields at those locations?

Peter Jamieson wrote:
Suggestons off the top of my head...

just use "Selection" instead of "oSel" (but qulaify it if necessary if
the
code is e.g. being run from Excel rather than WOrd

or try

Set oSel = Selection

before referencing oSel.

Peter Jamieson

"Drew" wrote in message
ups.com...
Hi Peter,

Actually the rsVariableDefinitions object is simply a recordset that
maps the variable name to the merge field to be used for that name.

What you say about selection object is exactly correct; my problem is
that I don't know how to set the oSel to be at the location I just
found. How do I do that??

thanks, Drew

Peter Jamieson wrote:
It would be easier to answer this if we knew anything about the
rsVariableDefinitions object (which I think is "proprietary"), but:
a. What is actually being returned by the statement

Let strField = rsVariableDefinitions("Field") ?
b. is anything setting oSel to be at the location you just found
(i.e.
the
Selection object might be at the correct location, but probably not
oSel)

Peter Jamieson

"Drew" wrote in message
ups.com...
I am attempting to convert a plain text document that contains
certain
variables as delimited by the "@" or other user specified delimiters
and I can't seem to get the merge fields to position themselves in
the
proper location. What currently happens is that the variables are
successfully removed, but the merge fields are all placed at the end
of
the document. Also, any merge fields that have more than one word
in
the field name is truncated to only the first word of the field's
name.
The code that I am using is below:

With objWord.Content.find
rsVariableDefinitions.MoveFirst
Do Until rsVariableDefinitions.EOF 'loop
through variable definition table and replace text with their merge
fields
.Execute strDelimiter &
rsVariableDefinitions!Variable & strDelimiter, , True, , , , True, ,
,
"", True 'Delete the variable placeholder
If .Found Then
Let strField =
rsVariableDefinitions("Field")
objWord.MailMerge.Fields.Add
oSel.Range, strField
End If
rsVariableDefinitions.MoveNext
Loop
End With

Can any one please help!

Thanks, Drew




  #8   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Replacing text with Merge Fields in Word

Great, thanks for the feedback.

Peter Jamieson

"Drew" wrote in message
oups.com...
Thank you, thank you, thank you! That's exactly what i needed. After
so many hours of frustration it's great to finally see this thing work!

Drew

Peter Jamieson wrote:
Ah you're working in Access :-)

But in any case, now I've had a proper look I don't think the existing
approach will take you where you want to go.

I would start with something more like the following:

Dim objWordApp As Word.Application
'Dim rngFound As Word.Range
' If you already have a reference to the Word Application, just use that
' instead of setting up this new one
Set objWordApp = ActiveDocument.Application
rsVariableDefinitions.MoveFirst
Do Until rsVariableDefinitions.EOF
objWordApp.Selection.HomeKey wdStory
objWordApp.Selection.Find.ClearFormatting
With objWordApp.Selection.Find
Do While .Execute( _
FindText:=strDelimiter & rsVariableDefinitions!Variable &
strDelimiter, _
Wrap:=wdFindContinue, _
Forward:=True) = True
'Set rngFound = Selection.Range
ActiveDocument.Fields.Add _
Range:=objWordApp.Selection.Range, _
Type:=wdFieldMergeField, _
Text:=rsVariableDefinitions("Field")
Loop
End With
rsVariableDefinitions.MoveNext
Loop

Some of that stuff may be surplus to requirements but I think it's closer
to
the mark.

Peter Jamieson

"Drew" wrote in message
ups.com...
I tried both methods and each time Access returned an error: 'Object
is deleted.' So I used Selection.range and this did not return an
error, but the merge fields are still placed at the end of the
document. Is there a way to return the character positions of each of
the variables in the document so that I could implicitly instruct
Access to place the merge fields at those locations?

Peter Jamieson wrote:
Suggestons off the top of my head...

just use "Selection" instead of "oSel" (but qulaify it if necessary if
the
code is e.g. being run from Excel rather than WOrd

or try

Set oSel = Selection

before referencing oSel.

Peter Jamieson

"Drew" wrote in message
ups.com...
Hi Peter,

Actually the rsVariableDefinitions object is simply a recordset that
maps the variable name to the merge field to be used for that name.

What you say about selection object is exactly correct; my problem
is
that I don't know how to set the oSel to be at the location I just
found. How do I do that??

thanks, Drew

Peter Jamieson wrote:
It would be easier to answer this if we knew anything about the
rsVariableDefinitions object (which I think is "proprietary"), but:
a. What is actually being returned by the statement

Let strField = rsVariableDefinitions("Field") ?
b. is anything setting oSel to be at the location you just found
(i.e.
the
Selection object might be at the correct location, but probably not
oSel)

Peter Jamieson

"Drew" wrote in message
ups.com...
I am attempting to convert a plain text document that contains
certain
variables as delimited by the "@" or other user specified
delimiters
and I can't seem to get the merge fields to position themselves
in
the
proper location. What currently happens is that the variables
are
successfully removed, but the merge fields are all placed at the
end
of
the document. Also, any merge fields that have more than one
word
in
the field name is truncated to only the first word of the field's
name.
The code that I am using is below:

With objWord.Content.find
rsVariableDefinitions.MoveFirst
Do Until rsVariableDefinitions.EOF
'loop
through variable definition table and replace text with their
merge
fields
.Execute strDelimiter &
rsVariableDefinitions!Variable & strDelimiter, , True, , , ,
True, ,
,
"", True 'Delete the variable placeholder
If .Found Then
Let strField =
rsVariableDefinitions("Field")
objWord.MailMerge.Fields.Add
oSel.Range, strField
End If
rsVariableDefinitions.MoveNext
Loop
End With

Can any one please help!

Thanks, Drew






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
Converting WordPerfect 12 files to Word 2003 Curious New Users 4 May 19th 23 02:48 PM
Why dont MS just f**king re-write Word from scratch? Its dogsh*t Word Hater Microsoft Word Help 33 May 5th 23 02:52 PM
take yet another lesson from wordperfect "reveal codes" wordperfect is superior Microsoft Word Help 5 May 11th 09 07:58 PM
WP merge file to Word sstires Tables 4 February 14th 06 06:26 PM
merge instructions from text file Steve Mailmerge 8 November 26th 05 03:31 AM


All times are GMT +1. The time now is 09:47 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"