Macro in Word to select line 23 and change the font

damianjmcgrath

Board Regular
Joined
Oct 31, 2008
Messages
72
Hello,

Can someone explain to me how to write a macro in Word to highlight line 23 and change the font of that line to Verdana.

The reason I want to do this is because I am using a ASK field to get the input of "Customer's Name". The field is then used at several points in the document using the REF field. However, the first use of it is in the letter's title which is in Bold and Verdana. The rest of the letter is in Non-Bold Arial.

However, when I input the customer's name into the inbox box, it adds the customers name everywhere in the document as Bold Verdana. Taking out MERGEFORMAT everywhere doesnt solve this, nor does adding it!

So, my next solution was to change the whole letter to Non-Bold Arial, and then after everything has run, add some extra code to make line 23 to Bold Verdana.

Has anyone got any advice on how to write that macro or fix the problem with the ASK and REF fields?

Thanks.
 

Some videos you may like

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Macropod

Retired Moderator
Joined
Aug 27, 2007
Messages
3,514
Hi damian,

Ordinarily, a cross-reference should adopt the format of the paragraph style in which it is located.

The Mergeformat switch is supposed to cause the cross-reference to retain the format of the source bookmark.

You can force the cross-reference to apply a different format by adding a Charformat switch. To do this:
1. select the cross-reference amd press Shift-F9. You should see something like '{REF BkMk}' or '{REF BkMk \* Mergeformat }', wher 'BkMk' is the name of the bookmark to which the cross-reference refers.
2. edit the field code so that you end up with '{REF BkMk \* Charformat }'
3. format the 'R' in 'REF' with the attributes you want the whole field to adopt
4. press F9 to update the field.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,085
Messages
5,599,650
Members
414,325
Latest member
kfg1287

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top