View Single Post
  #23  
Old December 11th, 2006, 08:55 PM posted to microsoft.public.word.mailmerge.fields
Peter Jamieson
external usenet poster
 
Posts: 4,550
Default Use DocVariable field to initiative numbering?

Yes, in this case that's probably because you're deleting everything, then
applying a style to the result :-)

So for example you might need

myRange.InsertCaption Label:="Figure"

/and then/

myRange.Style = "stylex"

it is only my personal opinion, but when you start playing with macros, at a
certain point you have to start working out for yourself how they work,
using the VB Editor, the debug tools, and the object model (Word's in this
case). Although plenty of pre-potted macros can do useful work, generally
speaking you have to adapt them for the specific problem you want to solve.
People can try to do it for you, but the results will rarely be reliable
because, apart from anything else, they do not have your "real-world" data
and cannot test with it.

Peter Jamieson


"Tom" wrote in message
ups.com...
Thanks Peter. Strangely, the macro seemed to work the first couple of
times, and then it stopped working. Now it only deletes the style, and
doesn't replace it. This is what I'm running:

Sub ScratchMacro()
Dim myRange As Range
Set myRange = ActiveDocument.Range
With myRange.Find
.Style = ActiveDocument.Styles("mystyle")
.MatchWholeWord = True
While .Execute
myRange.Delete
myRange.Style = "stylex"
Wend
End With
End Sub


Of course in my Word document I have both "mystyle" and "stylex"
defined in the styles.

I was also curious about how to run multiple style swaps in the same
macro -- for example, if I had a list of styles that I wanted to change
out with one click, how would I do that? Would I just include the next
macro before End Sub? I have tried that but it doesn't seem to work.
Thanks.

Tom