View Single Post
  #2   Report Post  
Jezebel
 
Posts: n/a
Default

When you insert a cross-reference to a heading, Word creates a hidden
bookmark for that heading. This is the _Ref12345678 part of your REF field
code. (The leading underscore is what makes it a hidden bookmark. You can
see these on the Bookmarks dialog by checking the 'Hidden Bookmarks'
checkbox.)

You can use this _Ref code to retrieve the heading itself, and thus its
style and other properties --

Dim pRef as string
:
pRef = mid$(oRg.Fields(1).Code, 6, 13)
ActiveDocument.Bookmarks.ShowHidden = TRUE
pStyle = ActiveDocument.Bookmarks(pRef).Range.Style


The Mid$() finction is dubious here -- it would be more reliable to use
Split() or Instr() to extract the reference.






"Max Moor" wrote in message
. 16...
Hi All,
I'm learning, little by little. I know that I can reference the text
that a cross reference field shows in the doc with:

strCode1 = oRg.Fields(1).Result.Text

Now, I'd like to be able to return the style of the header that the
cross-reference field refers to. For example, I search and find a cross
reference to a header. The code line above returns "Rubber Chickens."

In the document, Rubber Chickens' style is 'Heading 2'. Can I, in VB
code, get "Rubber Chickens" by way of the cross-reference field? I tried:

strCode2 = oRg.Fields(1).Result.Style

Of course, that gave me the style of the cross-reference field, not
the heading it refers to (as I wish).

Thanks for the help, Max