Link to home
Start Free TrialLog in
Avatar of Fi69
Fi69

asked on

Insert Cross Reference by vba and add \* Charformat to it

Hi experts

I'm inserting cross-references into a document from a userform, eg of the insert method below.
 Selection.InsertCrossReference ReferenceType:=strLabel, _
        ReferenceKind:=wdOnlyLabelAndNumber, ReferenceItem:=n

When it puts in a Table Caption for instance it inserts the formatting of the caption which is bolded. I've tried a few ways of getting around this (like applying unbold) but on update it reverts back to bold even with unbold character style applied. Then I stumbled across something tonight which I can add into the cross reference field that has been created. And that is \* Charformat . But I can't work out how to get it to automatically come in like this. At the moment I have to right-click on the cross-reference and then click Edit Field > Field Codes > Options > Field Specific Switches > then I paste \* Charformat  down in the field code text box. It is working when I do it this way but I need to set that step by code.

Experts how can I do this through VBA code as this is a very long-winded step?
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why are typos invisible before submission, and obvious afterwards?

"selction contin it," should be "selection contain it,"
Avatar of Fi69
Fi69

ASKER

I know exactly what you mean about the typos!

That code works brilliantly. I just had to add fld.update at the end so that it appeared correctly in my document.

Thank you so much Graham!