A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Mailmerge
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Use DocVariable field to initiative numbering?



 
 
Thread Tools Display Modes
  #21  
Old December 11th, 2006, 08:53 PM posted to microsoft.public.word.mailmerge.fields
Tom
external usenet poster
 
Posts: 61
Default Use DocVariable field to initiative numbering?

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

  #22  
Old December 11th, 2006, 08:53 PM posted to microsoft.public.word.mailmerge.fields
Tom
external usenet poster
 
Posts: 61
Default Use DocVariable field to initiative numbering?

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

  #23  
Old December 11th, 2006, 09: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



  #24  
Old December 12th, 2006, 05:28 AM posted to microsoft.public.word.mailmerge.fields
Tom
external usenet poster
 
Posts: 61
Default Use DocVariable field to initiative numbering?

Thanks Peter. Yes, I know, I need to start figuring out macros for
myself. Do you recommend just using the help file in the Visual Basic
Editor, or using some other tutorial book? I didn't realize how
powerful macros were until this past week. I really appreciate your
responses to my questions. I have learned quite a bit from this forum.

  #25  
Old December 12th, 2006, 09:48 AM posted to microsoft.public.word.mailmerge.fields
Peter Jamieson
external usenet poster
 
Posts: 4,550
Default Use DocVariable field to initiative numbering?

Hi Tom,

Do you recommend just using the help file in the Visual Basic
Editor, or using some other tutorial book?


IMO the best way to approach learning is quite personal - but
a. something to bear in mind is that VBA is in theory on its way out, to be
superseded by VB.NET or some usuch on Windows and (in effect) Applescript on
Mac. It's still there in Office 2007, but there are an increasing number of
things you can't do without resorting to .NET. That said, for the kind of
things you're doing at the moment that's probably a bit of a red herring.
b. there /is/ a lot of info in the Help files accessible via VBE, about
both VBA and the VBA as it applies to the Word object model. Word Help also
contains a lot of info. Also, I refer to the View|Object Browser function in
VBE a lot - understanding how Word's object model really works is critical.
c. Personally, I tend to learn by experiment, but usually find it's useful
to start with an overview of a programming language. I can't recommend one,
but I expect you'll find some pointers in VBA-oriented groups here. As fr as
I know, there are no good books specifically about Word VBA or the Word
object model in English (you can search www.amazon.de for the ones in German
by CIndy Meister, myself, and others if you happen to read German:-)).
d. the Word MVPs site at http://word.mvps.org has plenty of useful examples
(and the more general http://www.mvps.org site can also be useful). There
are several programming-oriented groups similar to this one where you're
more likely to get good general-purpose VBA help (and you can search all
these groups using Google groups).
e. A few things I'd say about VBA and object models which it took me a long
time to learn:
- you won't usually find documentation in the object model about the
sequence of objects in collections. In some cases they do appear to be in
the "intuitively obvious" sequence and in some cases you may as well rely on
that sequence even though it isn't documented. I found this the single most
irritating barrier to using VBA when it first appeared.
- some objects in the Word object model correspond to objects that persist
in the Word document (for example, Document variables) but others are not
persisted and are only available while your code is running (e.g. Range
objects). It should be reasonably obvious which is which, but at first it's
easy to get it wrong.
- you will probably end up using Range objects a lot. IMO it is one of the
worst-designed objects in Word. It's far more awkward to use than it needs
to be, and is far too sensitive to the current view, coping particularly
badly with fields. But since you can't really avoid it, it's probably worth
spending quite a lot of time learning to use that one object.

Peter Jamieson
-
"Tom" wrote in message
ups.com...
Thanks Peter. Yes, I know, I need to start figuring out macros for
myself. Do you recommend just using the help file in the Visual Basic
Editor, or using some other tutorial book? I didn't realize how
powerful macros were until this past week. I really appreciate your
responses to my questions. I have learned quite a bit from this forum.



  #26  
Old December 12th, 2006, 02:15 PM posted to microsoft.public.word.mailmerge.fields
Tom
external usenet poster
 
Posts: 61
Default Use DocVariable field to initiative numbering?

Thanks, Peter, for the useful links and reading recommendations. I will
definitely check some of them out.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:22 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.