Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Converting WordPerfect 12 files to Word 2003 | New Users | |||
Why dont MS just f**king re-write Word from scratch? Its dogsh*t | Microsoft Word Help | |||
take yet another lesson from wordperfect "reveal codes" | Microsoft Word Help | |||
WP merge file to Word | Tables | |||
merge instructions from text file | Mailmerge |