Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
Can the DocVariable field be used to somehow initiate Figure numbering?
Let me explain. Suppose I have the phrase XYZ in a document. I want to integrate a macro such that each place XYZ appears, a Figure number is inserted instead. In other words, the macro would say, Find XYZ, and replace with the caption field. Is this possible? If so, it might enable me to run a macro to fix a RoboHelp output to include Figure captions. |
#2
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
Maybe I want to use an IF Then statement instead. All of this is new to
me and I'm trying to understand it. Something like: {IF "XYZ" Then {SEQ Figure \ *Arabic}} Can someone point me to a good tutorial on if then statements? In my document, XYZ would be a unique phrase that I'd want to replace with a figure caption. |
#3
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
Typicaly a Figure number would contain something like the following (it
depends on the type of reference you choose to have); Figure { SEQ Figure \*Arabic } In that case you should be able to start the sequence numbering by inserting the following nested field at the beginning of your document: { SEQ Figure \r{ DOCVARIABLE myvariable } \h } (depending on what you are doing it might be better to put your starting number in a Document Property and use the following instead: { SEQ Figure \r{ DOCPROPERTY myproperty } \h } ) Let me explain. Suppose I have the phrase XYZ in a document. I want to integrate a macro such that each place XYZ appears, a Figure number is inserted instead. In other words, the macro would say, Find XYZ, and replace with the caption field. This seems to be something else altogether. If you just want to replace every occurence of XYZ in a document with the caption field, the simplest way is probably a. create the caption text and fields you want (e.g. Figure { SEQ Figure \*Arabic } b. Edit|Copy that stuff so it's on the clipboard c. use Edit|Replace to replace XYZ by ^c (i.e. the clipboard contents). If you need to do it using a macro, things get a bit harder. Peter Jamieson "Tom" wrote in message ups.com... Can the DocVariable field be used to somehow initiate Figure numbering? Let me explain. Suppose I have the phrase XYZ in a document. I want to integrate a macro such that each place XYZ appears, a Figure number is inserted instead. In other words, the macro would say, Find XYZ, and replace with the caption field. Is this possible? If so, it might enable me to run a macro to fix a RoboHelp output to include Figure captions. |
#4
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
Thanks Peter. The method of copy and replace seems to do the trick. I
didn't know you could do the ^c function to insert a field like that. Thanks again! This forum is excellent. This seems to be something else altogether. If you just want to replace every occurence of XYZ in a document with the caption field, the simplest way is probably a. create the caption text and fields you want (e.g. Figure { SEQ Figure \*Arabic } b. Edit|Copy that stuff so it's on the clipboard c. use Edit|Replace to replace XYZ by ^c (i.e. the clipboard contents). |
#5
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
Tom,
I don't see how what a DocVariable has to do with numbering figures. You want to find "XYZ" and replace with a numbered figure caption number correct? Try: 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 Tom wrote: Can the DocVariable field be used to somehow initiate Figure numbering? Let me explain. Suppose I have the phrase XYZ in a document. I want to integrate a macro such that each place XYZ appears, a Figure number is inserted instead. In other words, the macro would say, Find XYZ, and replace with the caption field. Is this possible? If so, it might enable me to run a macro to fix a RoboHelp output to include Figure captions. |
#6
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
I would like to better understand the DOCPROPERTY and DOCVARIABLE
fields. You gave the following examples: { SEQ Figure \r{ DOCVARIABLE myvariable } \h } (depending on what you are doing it might be better to put your starting number in a Document Property and use the following instead: { SEQ Figure \r{ DOCPROPERTY myproperty } \h } ) I'm just not sure how to implement this. I assume "myvariable" and "myproperty" are unique words I define. But where are they stored? How do I define them? What exactly do they do? I'm still in the dark here. Also, I realized the figure captions find-and-replace method only solves part of the problem. In our HTML document, we have phrases like this: "See Figure 1" and then below the figure we write "Figure 1." When I did the find and replace method, it did sequentially number the figures, but how would I implement the "See Figure 1" part? That seems impossible. |
#7
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
Hi Tom,
Well, I'd assumed you knew what a docvariable was because you mentioned them in the subject line of your post. But maybe you'd picked that up from somewhere else, and maybe it's completely irrelevant. But roughly speaking, You can create document properties and set/modify their values using the File|Properties dialog box. Personally I wouldn't use any type except "string" unless I had a good reason. Further, you can modify document properties programmatically, and view their values, even if you don't have Word (i.e. the properties are stored in structures that do not rely on Word). Sometimes, that's a bonus, but I suspect it's not that important in this case. Document variables are named values stored within Word. You can't set them up or maintain them using the standard user interface, and you can only get at them programmatically by using the Word object model. So they are perhaps better if you don't want users to modify their values. The DOCVARIABLE and DOCPROPERTY fields simply insert the values of the specified document variables and document properties. If you want to experiment with these field types I suggest you stick to DOCPROPERTY in the first instance as you can play with these without resorting to VBA. Also, I realized the figure captions find-and-replace method only solves part of the problem. In our HTML document, we have phrases like this: "See Figure 1" and then below the figure we write "Figure 1." When I did the find and replace method, it did sequentially number the figures, but how would I implement the "See Figure 1" part? That seems impossible. Yes. However, how to maintain these references depends on what you're doing - you mention "your HTML document". Are you starting with that and trying to create a Word document from it, or what? Peter Jamieson "Tom" wrote in message ups.com... I would like to better understand the DOCPROPERTY and DOCVARIABLE fields. You gave the following examples: { SEQ Figure \r{ DOCVARIABLE myvariable } \h } (depending on what you are doing it might be better to put your starting number in a Document Property and use the following instead: { SEQ Figure \r{ DOCPROPERTY myproperty } \h } ) I'm just not sure how to implement this. I assume "myvariable" and "myproperty" are unique words I define. But where are they stored? How do I define them? What exactly do they do? I'm still in the dark here. Also, I realized the figure captions find-and-replace method only solves part of the problem. In our HTML document, we have phrases like this: "See Figure 1" and then below the figure we write "Figure 1." When I did the find and replace method, it did sequentially number the figures, but how would I implement the "See Figure 1" part? That seems impossible. |
#8
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
Greg,
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 The macro code you wrote works much more quickly and powerfully, even formatting the XYZ text in caption styles. Thanks! Here's a little more background with what I'm trying to accomplish, and why I was wondering about DocVariables. I'm a technical writer trying to single source with Robohelp. Robohelp is an HTML-based application that stores everything in discrete topics. It also outputs to Word. When it outputs to Word, it strings together all the topics in one long Word document. The output to Word is problematic for two main reasons: Captions and references to those captions -- Using the code and techniques you and Peter explained, I can easily add captions to every figure (by replacing XYZ with the captions). However, in the body of the text, we often write "See Figure 1 below" or "See Figure 5 below." How would I retain the "See Figure 5" part? A similarly related problem is cross references. Let's say I want to refer a reader to a topic on another page. In HTML, one simply says "See Creating Documents" and makes it a link to the topic. However, in the print output, "See Creating Documents" doesn't include any page references. The topic could be on page 5 or 50. How could I set it up so that the print output said "See Creating Documents on page 6" (where page 6 is where the heading text appears that contains this topic)? I have been told that it is possible to do this (cross references) through a DocVariable. This is why I keep asking about it. If you have a solution for cross references that works, it would make quite a few technical writers happy. Any ideas? |
#9
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
Peter,
Thanks for the explanations about the differences between DocVariables and DocProperties. That does make it a little clearer. You asked, However, how to maintain these references depends on what you're doing - you mention "your HTML document". Are you starting with that and trying to create a Word document from it, or what? To view an HTML document similar to the ones I create, open up Internet Explorer 6.0 and go to Help Contents and Index. What loads is an Web Help application of some kind. RoboHelp essentially creates the same online help tool. RoboHelp also exports all of these topics to Microsoft Word. Where RoboHelp falls short is in converting links to cross references. It just doesn't seem to do it, and I'm not sure of any workaround. That's why I was thinking that maybe if I stored some kind of variable in the HTML, I could convert it into a unique cross reference in Word. But that doesn't really seem probable, right? |
#10
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
Peter,
Thanks for the explanations about the differences between DocVariables and DocProperties. That does make it a little clearer. You asked, However, how to maintain these references depends on what you're doing - you mention "your HTML document". Are you starting with that and trying to create a Word document from it, or what? To view an HTML document similar to the ones I create, open up Internet Explorer 6.0 and go to Help Contents and Index. What loads is an Web Help application of some kind. RoboHelp essentially creates the same online help tool. RoboHelp also exports all of these topics to Microsoft Word. Where RoboHelp falls short is in converting links to cross references. It just doesn't seem to do it, and I'm not sure of any workaround. That's why I was thinking that maybe if I stored some kind of variable in the HTML, I could convert it into a unique cross reference in Word. But that doesn't really seem probable, right? |
#11
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
Actually, I see that someone does have a solution for cross-references,
but it isn't ideal. Can any of you improve upon the method here? http://www.grainge.org/pages/authori...m#broken_links |
#12
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
Tom,
What I'd /probably do in this scenario is try to expand on Greg's macro and look separately for references (e.g. "See Figure nnn") and the figure identifiers themselves, then mark them in some way that would enable me to match them up. Greg may have some further ideas but I'll have to think about how I'd approach this and time marches on on this side of the pond... Apart from that, I suppose I might want to take another look at RoboHelp just to be sure that I hadn't missed some referencing feature that would help me maintain references when I output to Word. But since I don't have that software, I couldn't really say what I'd be looking for... Peter Jamieson "Tom" wrote in message ups.com... Peter, Thanks for the explanations about the differences between DocVariables and DocProperties. That does make it a little clearer. You asked, However, how to maintain these references depends on what you're doing - you mention "your HTML document". Are you starting with that and trying to create a Word document from it, or what? To view an HTML document similar to the ones I create, open up Internet Explorer 6.0 and go to Help Contents and Index. What loads is an Web Help application of some kind. RoboHelp essentially creates the same online help tool. RoboHelp also exports all of these topics to Microsoft Word. Where RoboHelp falls short is in converting links to cross references. It just doesn't seem to do it, and I'm not sure of any workaround. That's why I was thinking that maybe if I stored some kind of variable in the HTML, I could convert it into a unique cross reference in Word. But that doesn't really seem probable, right? |
#13
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
Tom,
Sorry I can't help here. I don't even know what HTML is and without a sample document that I could run this code on, I can't make sense out of it. Tom wrote: Actually, I see that someone does have a solution for cross-references, but it isn't ideal. Can any of you improve upon the method here? http://www.grainge.org/pages/authori...m#broken_links |
#14
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
OK, now back in action for a few hours...
1. Do you need to set a "starting" Figure number as your original post suggests, or will that number always actually be 1? 2. If RoboHelp is just converting a number of separate articles (or whatever it calls them) into a single Word document, does that mean that you can end up with multiple "Figure 1" captions in the same document, e.g. blah blah (See Figure 1) Figure 1 Figure 2 blah blah (see Figure 2) blah blah new article(See Figure 1) Figure 1 and so on 3. If so, is there any obvious way to tell where a new article starts to avoid making the wrong references? (it seems likely that if the document is constructed from short articles you may get a number of "Figure 1" references and items in succession, but from different articles. Peter Jamieson "Peter Jamieson" wrote in message ... Tom, What I'd /probably do in this scenario is try to expand on Greg's macro and look separately for references (e.g. "See Figure nnn") and the figure identifiers themselves, then mark them in some way that would enable me to match them up. Greg may have some further ideas but I'll have to think about how I'd approach this and time marches on on this side of the pond... Apart from that, I suppose I might want to take another look at RoboHelp just to be sure that I hadn't missed some referencing feature that would help me maintain references when I output to Word. But since I don't have that software, I couldn't really say what I'd be looking for... Peter Jamieson "Tom" wrote in message ups.com... Peter, Thanks for the explanations about the differences between DocVariables and DocProperties. That does make it a little clearer. You asked, However, how to maintain these references depends on what you're doing - you mention "your HTML document". Are you starting with that and trying to create a Word document from it, or what? To view an HTML document similar to the ones I create, open up Internet Explorer 6.0 and go to Help Contents and Index. What loads is an Web Help application of some kind. RoboHelp essentially creates the same online help tool. RoboHelp also exports all of these topics to Microsoft Word. Where RoboHelp falls short is in converting links to cross references. It just doesn't seem to do it, and I'm not sure of any workaround. That's why I was thinking that maybe if I stored some kind of variable in the HTML, I could convert it into a unique cross reference in Word. But that doesn't really seem probable, right? |
#15
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
As far as cross references go, I found a really cool macro at Peter
Grainge's site (www.grainge.org under RoboHelp Printed Documentation Print Issues). Here's what it does: In your document, if you have hyperlinks to different heading titles, and if those hyperlinks have the same wording as the headings they point to, the macro converts the hyperlink into a cross reference with a page number. For example "For more information, see Heading Styles." (where Heading Styles is a hyperlink to another heading) becomes "For more information, see Heading Styles on page 5 (or whatever page that heading happens to be at). I found just one little problem with the macro code, but my VB friend told me to comment out a little bit of code after the word true about 50 lines down, and then it worked. I'm posting the revised code here in case anyone else is interested: Sub RebuildLinks() ' This bit added to set Smart Cut and Paste off while macro runs ' Thanks to JScher at Woody's Lounge, www.wopr.com Dim blnSmartCutAndPaste As Boolean blnSmartCutAndPaste = Options.SmartCutPaste Options.SmartCutPaste = False ' This macro written by Tannis Turnbull. RH Forum Dim myHeadings() As String 'Dim myPageNumbers() As String Dim i As Integer 'store all heading information myHeadings = ActiveDocument.GetCrossReferenceItems(wdRefTypeHea ding) 'move the cursor to section 3 Selection.HomeKey Unit:=wdStory Selection.Move wdSection, 2 'search for text with hyperlink style Selection.Find.ClearFormatting Selection.Find.Style = ActiveDocument.Styles("Hyperlink") With Selection.Find ..Text = "" ..Replacement.Text = "" ..Forward = True ..Wrap = wdFindContinue ..Format = True ..MatchCase = False ..MatchWholeWord = False ..MatchWildcards = False ..MatchSoundsLike = False ..MatchAllWordForms = False ..Execute FindText:="", Format:=True While .Found = True 'loop around refs to find the right one and update link For i = 1 To UBound(myHeadings) If Selection = Trim(myHeadings(i)) Then 'update the style with a real link and page info Selection.Delete Selection.InsertCrossReference ReferenceType:="Heading", ReferenceKind:= _ wdContentText, ReferenceItem:=CStr(i), InsertAsHyperlink:=True, _ IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" " ' in Word XP amend the line above to IncludePosition:=False Selection.TypeText Text:=" on page " Selection.InsertCrossReference ReferenceType:="Heading", ReferenceKind:= _ wdPageNumber, ReferenceItem:=CStr(i), InsertAsHyperlink:=True ', _ 'IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" " ' in Word XP amend the line above to IncludePosition:=False End If Next i ..Execute Wend End With ' Next line added as part of JScher's change, restores setting to what user had before. Options.SmartCutPaste = blnSmartCutAndPaste End Sub |
#16
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
Peter, let me provide a better picture of what I want my document to
look like. Here is the gist of it: Blah blah blah blah blah blah blah. See Figure 1. [image] Figure 1. Image caption blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah. See Figure 2. [image] Figure 2. Image caption blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah. See Figure 3. [image] Figure 3. Image caption The Figure numbering does not start over (in other words, there is only one Figure 1 in the entire document). Thanks to the earlier code you guys posted on automating captions, the captions part works great. The only part that remains is the "See Figure 1" reference that precedes the caption. It becomes slightly more complicated because in my RoboHelp source file, I may have 200 topics and only choose to compile 150 of them (depending on the needs of the audience). Here is what I think might work -- I will label each "See Figure 1", "See Figure 2" and so on as "See FigureZ." (All the same.) Then here's what I want the code to do: Look for first instance of the word "See FigureZ" and change it to See Figure 1. Stop. Now look for the first instance of "See FigureZ" and change it to See Figure 2. Stop. Now look for the first instance of "See FigureZ" and change it to See Figure 3. Stop. Now look for the first instance of "See FigureZ" and change it to Figure 4. Repeat until 100 Figure replacements or so. I figure that after the first command changes the See FigureZ to Figure 1, then upon second looping, the first FigureZ instance that appears will be placed exactly where Figure 2 should appear. Can any of you write a macro that does this? I would so appreciate it. Or do you have a better solution? Thanks so much for your help on this. This seems like the last piece to the puzzle. |
#17
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
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. |
#18
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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. |
#19
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
Peter,
The macro code you wrote works perfectly! Thanks. It's really impressive to see all of these macros in action. I'm planning to put them all together into a template that technical writers can easily use to convert RoboHelp generated source material into a Word document. I have a related question. In the following code, how would I change the line myRange.InsertCaption Label:="Figure" to replace the "mystyle" with another style, such as "stylex"? In other words, how do I swap styles? (I thought it would be something like myRange.InsertStyleRef ("stylex") but it didn't work.) Sub ScratchMacro() Dim myRange As Range Set myRange = ActiveDocument.Range With myRange.Find .Style = ActiveDocument.Styles("mystyle") .MatchWholeWord = True While .Execute myRange.Delete myRange.InsertCaption Label:="Figure" Wend End With End Sub Also, let's say I have 15 style swaps that I want to make with one macro. I'm assuming that i just remove the words "End Sub" from the end, and add the additional macro code, but without the additional macro's name (e.g., Sub ScratchMacro())? Thanks. |
#20
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
"mystyle" with another style, such as "stylex"? In other words, how do I swap styles? (I thought it would be something like myRange.InsertStyleRef ("stylex") but it didn't work.) What you probably need is myRange.Style = "stylex" However, it depends partly on whether you want to apply a style to the entire paragraph or the text in the range (and/or whether you are applying a paragraph style or a character style) Peter Jamieson "Tom" wrote in message ps.com... Peter, The macro code you wrote works perfectly! Thanks. It's really impressive to see all of these macros in action. I'm planning to put them all together into a template that technical writers can easily use to convert RoboHelp generated source material into a Word document. I have a related question. In the following code, how would I change the line myRange.InsertCaption Label:="Figure" to replace the "mystyle" with another style, such as "stylex"? In other words, how do I swap styles? (I thought it would be something like myRange.InsertStyleRef ("stylex") but it didn't work.) Sub ScratchMacro() Dim myRange As Range Set myRange = ActiveDocument.Range With myRange.Find .Style = ActiveDocument.Styles("mystyle") .MatchWholeWord = True While .Execute myRange.Delete myRange.InsertCaption Label:="Figure" Wend End With End Sub Also, let's say I have 15 style swaps that I want to make with one macro. I'm assuming that i just remove the words "End Sub" from the end, and add the additional macro code, but without the additional macro's name (e.g., Sub ScratchMacro())? Thanks. |
#21
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
Use DocVariable field to initiative numbering?
Thanks, Peter, for the useful links and reading recommendations. I will
definitely check some of them out. |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Setting Date property in a form field | Microsoft Word Help | |||
Insert numbering field in merged Word document (invoice nos)? | Mailmerge | |||
Caption numbering in chapters | Microsoft Word Help | |||
Cannot printing DocVariable Field | Microsoft Word Help | |||
Numbering - skip a level | Microsoft Word Help |