Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / November 2004

Tip: Looking for answers? Try searching our database.

Cut and paste merge field codes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dixie - 06 Nov 2004 00:18 GMT
Is there a simple way  of copying a set of merge field conditions oout of a
mail merge document and then pasting the codes in a way someone can read the
code, rather than the results of the code?  It'd be really good for posting
code in a newsgroup.  It can be very tedious typing a long sequence of code
you have already typed in Word.
macropod - 06 Nov 2004 06:54 GMT
Hi Dixie,

If you select the field that you want to copy, then run the following macro,
a 'plain text' version of the field will be placed in the clipboard for
pasting.

Cheers

Sub FieldCodeToString()
   Dim Fieldstring As String, NewString As String, CurrChar As String
   Dim CurrSetting As Boolean, fcDisplay As Object
   Dim MyData As DataObject, X As Integer
   NewString = ""
   Set fcDisplay = ActiveWindow.View
   Application.ScreenUpdating = False
   CurrSetting = fcDisplay.ShowFieldCodes
   If CurrSetting <> True Then fcDisplay.ShowFieldCodes = True
   Fieldstring = Selection.Text
   For X = 1 To Len(Fieldstring)
       CurrChar = Mid(Fieldstring, X, 1)
       Select Case CurrChar
           Case Chr(19)
               CurrChar = "{"
           Case Chr(21)
               CurrChar = "}"
           Case Else
       End Select
       NewString = NewString + CurrChar
   Next X
   Set MyData = New DataObject
   MyData.SetText NewString
   MyData.PutInClipboard
   fcDisplay.ShowFieldCodes = CurrSetting
End Sub

> Is there a simple way  of copying a set of merge field conditions oout of a
> mail merge document and then pasting the codes in a way someone can read the
> code, rather than the results of the code?  It'd be really good for posting
> code in a newsgroup.  It can be very tedious typing a long sequence of code
> you have already typed in Word.
dixie - 06 Nov 2004 07:15 GMT
Hi macropod - nice name :-). Bear with me here, I've never done this before.
I usually only use Word to do some mail merge from Access.  I entered the
code in as a macro and called it FieldCodeToString.  I then called up that
macro and ran it.  It stopped at the line:
Dim MyData As DataObject, X As Integer
with aUser-defined type not defined.  Now if this was in Access, I would
think I didn't perhaps have the right dll files installed.  Is that what is
causing this to happen?

dixie

> Hi Dixie,
>
[quoted text clipped - 46 lines]
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.788 / Virus Database: 533 - Release Date: 1/11/2004
dixie - 06 Nov 2004 07:38 GMT
Just in case it's relevant - using Word 2000.

dixie

> Hi macropod - nice name :-). Bear with me here, I've never done this
> before. I usually only use Word to do some mail merge from Access.  I
[quoted text clipped - 58 lines]
>> Checked by AVG anti-virus system (http://www.grisoft.com).
>> Version: 6.0.788 / Virus Database: 533 - Release Date: 1/11/2004
macropod - 06 Nov 2004 07:41 GMT
Hi Dixie,

Since this is a macro that I use from time to time, I know it works. You
should be able to simply copy and paste it into a Word vba module (called up
via Alt-F11), without having to name it.

Alternatively, perhaps you don't have all the required vba library
references defined. If you press Alt-F11, you can see them listed under
Tools|References. In my case, the checked ones are:
. visual basic for applications
. Microsoft Word # object library (where # is your current Word version)
. OLE automation
. Microsoft Office # object library (where # is your current Word version)
. Microsoft Forms 2.0 object library
If you make sure that you have at least these checked, things should work
OK.

Cheers

> Hi macropod - nice name :-). Bear with me here, I've never done this before.
> I usually only use Word to do some mail merge from Access.  I entered the
[quoted text clipped - 57 lines]
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.788 / Virus Database: 533 - Release Date: 1/11/2004
dixie - 06 Nov 2004 07:49 GMT
Followed that to a 'T'.  But still same result - I don't have the reference
Microsoft Forms 2.0 - it seems to be missing from the list.  That might be
it!

dixie

> Hi Dixie,
>
[quoted text clipped - 87 lines]
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.788 / Virus Database: 533 - Release Date: 1/11/2004
dixie - 06 Nov 2004 07:53 GMT
The only other thing that might be different I guess is that this is a
template, not a .doc file.

dixie

> Followed that to a 'T'.  But still same result - I don't have the
> reference Microsoft Forms 2.0 - it seems to be missing from the list.
[quoted text clipped - 98 lines]
>> Checked by AVG anti-virus system (http://www.grisoft.com).
>> Version: 6.0.788 / Virus Database: 533 - Release Date: 1/11/2004
macropod - 06 Nov 2004 12:06 GMT
Hi Dixie,

In that case, scroll down through the available list of vba references and
add the 'Microsoft Forms 2.0 object' by clicking on it.

Cheers

> Followed that to a 'T'.  But still same result - I don't have the reference
> Microsoft Forms 2.0 - it seems to be missing from the list.  That might be
[quoted text clipped - 93 lines]
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.788 / Virus Database: 533 - Release Date: 1/11/2004
dixie - 06 Nov 2004 13:07 GMT
But it is not in the list of references!!

dixie

> Hi Dixie,
>
[quoted text clipped - 120 lines]
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.788 / Virus Database: 533 - Release Date: 1/11/2004
Graham Mayor - 06 Nov 2004 13:20 GMT
I had high hopes for this macro, but it doesn't work for me either and I do
have all the quoted references checked. I get no error messages, but no
conversion either.

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

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

> Hi Dixie,
>
[quoted text clipped - 101 lines]
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.788 / Virus Database: 533 - Release Date: 1/11/2004
macropod - 07 Nov 2004 01:12 GMT
Hi Graham,

To use the macro, you simply select the field to be converted, then run the
macro to put the 'plain text' version into the clipboard. Then simply select
wherever you want the output to go, be it Word, notepad, your email client,
or whatever, and paste the results (eg Ctrl-V) into it.

In Dixie's case, the lack of a 'Microsoft Forms 2.0 object' in the available
references suggests that some of the Word/Office 2000 functionality may not
have been installed. Any idea which components install that library?

Cheers

> I had high hopes for this macro, but it doesn't work for me either and I do
> have all the quoted references checked. I get no error messages, but no
[quoted text clipped - 105 lines]
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.788 / Virus Database: 533 - Release Date: 1/11/2004
dixie - 07 Nov 2004 05:02 GMT
YES!!  I got it to work.  I did a browse for the Microsoft Forms 2.0
reference and I found a C:\WINDOWS\system32\FM20.dll and just selected it.
Voila, the reference Microsoft Forms 2.0 Object Library was showing as
ticked.  Then I had a go at highlighting the Field codes and running the
macro.  I then went to another empty word document and did a CTRL V to paste
it and there were all the field codes using the normal {} keys instead of
the proper CTRL F9 ones.  Macropod, you're a genius.

dixie

> Hi Graham,
>
[quoted text clipped - 129 lines]
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.788 / Virus Database: 533 - Release Date: 2/11/2005
dixie - 07 Nov 2004 05:34 GMT
Right, got it working fine now, but it only works on the one template file.
Can I install the macro code so that it works universally on any mailmerge
document on my computer.  If so, where do I put the code?

dixie

> Hi Graham,
>
[quoted text clipped - 129 lines]
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.788 / Virus Database: 533 - Release Date: 2/11/2005
Graham Mayor - 07 Nov 2004 08:08 GMT
Put it in normal.dot

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

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

> Right, got it working fine now, but it only works on the one template
> file. Can I install the macro code so that it works universally on
[quoted text clipped - 146 lines]
>> Checked by AVG anti-virus system (http://www.grisoft.com).
>> Version: 6.0.788 / Virus Database: 533 - Release Date: 2/11/2005
dixie - 07 Nov 2004 05:44 GMT
Another question comes to mind now that this is working.  Can you sort of do
that in reverse, such that your could publish the code in an email or text
message and it could be pasted into a mail merge document and then have the
ordinary brackets changed to proper field code brackets again, meaning that
the person would not have to manually copy the code into the mail merge
document.

dixie

> Hi Graham,
>
[quoted text clipped - 129 lines]
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.788 / Virus Database: 533 - Release Date: 2/11/2005
Graham Mayor - 07 Nov 2004 08:07 GMT
No who feels stupid? :(
Good one!
It shouldn't take much effort to add the code to paste the result in the
document now I know what it is supposed to be doing ;)

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

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

> Hi Graham,
>
[quoted text clipped - 136 lines]
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.788 / Virus Database: 533 - Release Date: 2/11/2005
dixie - 07 Nov 2004 05:30 GMT
When I finally found the right dll and got the forms 2.0 reference in place,
I tried to use it and the first time it didn't work for me either.  It was
then I realised that when macropod said select the field, he meant totally
selected as in highlighted by sweeping the mouse cursor through it.  If you
just click in it, it does all go grey, but it doesn't work.

dixie

>I had high hopes for this macro, but it doesn't work for me either and I do
> have all the quoted references checked. I get no error messages, but no
[quoted text clipped - 105 lines]
>> Checked by AVG anti-virus system (http://www.grisoft.com).
>> Version: 6.0.788 / Virus Database: 533 - Release Date: 1/11/2004
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.