View Single Post
  #18   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Use DocVariable field to initiative numbering?

OK, I think what you're saying is that
a. you want to number your figures sequentially
b. you always have exactly one "See Figure X" for each Figure X
c. the "See figure" reference always precedes the Figure number it's
referrring to

But if that is the case, I don't really understand why you need to insert
"proper" figure references using SEQ fields or whatever, particlarly if
RoboHelp is always generating the correct sequence numbers with no gaps. Why
not just do all the numbering directly from your macro (and not use any
fields)?

The main reason I can think of is that you want to do the Figure numbering
"properly" so that someone can take the Word document and add stuff
including other references. But if that's the case, they won't be able to
use the same referencing mechanism you are providing to them, brcause one
extra { AutoNum \*Arabic } in the document will throw the whole scheme out.

But to answer your questions...

Sub ScratchMacro()
Dim myRange As Range
Set myRange = ActiveDocument.Range
With myRange.Find
.Text = "XYZ"
.MatchWholeWord = True
While .Execute
myRange.Delete
myRange.InsertCaption Label:="Figure"
Wend
End With
End Sub

Instead of writing .Text, can I use a style there?


Yes, you can use

..Style = ActiveDocument.Styles("mystyle")

And instead of using InsertCaption Label:="Figure", what would I use to
insert the AutoNum tag? I tried InsertAutoNum but it didn't work.


You can use

myRange.Fields.Add range:=myRange, type:=wdfieldempty, text:="AutoNum
\*Arabic", preserveformatting:=false

You should be able to do both operations in succession using something like

Sub ScratchMacro()
Dim myRange As Range
Set myRange = ActiveDocument.Range
With myRange.Find
.Text = "XYZ"
.MatchWholeWord = True
While .Execute
myRange.Delete
myRange.InsertCaption Label:="Figure"
Wend
End With
' Following line may be unnecessary, or
' you may need to do more to reset the Find object
Set myRange = Nothing
Set myRange = ActiveDocument.Range
With myRange.Find
.Style = ActiveDocument.Styles("mystyle")
.MatchWholeWord = True
While .Execute
myRange.Delete
myRange.Fields.Add _
range:=myRange, _
type:=wdfieldempty, _
text:="AutoNum \*Arabic", _
preserveformatting:=false
Wend
End With
End Sub

(But I haven't tested it!)

Peter Jamieson

"Tom" wrote in message
oups.com...
I think I can easily accomplish my see references using this method:

1. In my RoboHelp file, tag the "1" in the phrase See Figure 1 with a
unique style.
2. When I export to Word, the style carries over.
3. In Word, type { AutoNum \*Arabic }. Or go to Insert Field
AutoNum and see the same code. Select this field code and copy it to
the clipboard.
4. Do a find and replace of the unique style with the AutoNum field
code.

This numbering won't interfere with captions or lists.

I'd like to make it into a macro that I can just run.

Greg, earlier you wrote this code:

Sub ScratchMacro()
Dim myRange As Range
Set myRange = ActiveDocument.Range
With myRange.Find
.Text = "XYZ"
.MatchWholeWord = True
While .Execute
myRange.Delete
myRange.InsertCaption Label:="Figure"
Wend
End With
End Sub

Instead of writing .Text, can I use a style there?
And instead of using InsertCaption Label:="Figure", what would I use to
insert the AutoNum tag? I tried InsertAutoNum but it didn't work.