PDA

View Full Version : Figure Numbering Macro



nt3
03-11-2014, 07:14 AM
Hi All,

This is my first post to this forum, so I apologize if something is unclear. I have programming experience and I understand the very basics of creating macros in Word, but I'm new to VBA. I'm running Word 2007 on Windows 7.

Basically, I want to create a simple macro to go through a document and number figures. I thought an easy way to do this would be to create labels and references (/rF{} to refer to a figure and /lF{} to label a figure, kind of like in LaTeX). Suppose the text of my document is the following:


In Figure /rF{BadFig} we can see such and such. However, in Figure /rF{GoodFig} we see something else.

GoodFig goes here.
Figure /lF{GoodFig}. Caption stuff.

BadFig goes here.
Figure /lF{BadFig}. Caption stuff.

Figure /rF{GoodFig} is so much better than Figure /rF{BadFig}.


I would want this to be changed to the following after running the macro:


In Figure 2 we can see such and such. However, in Figure 1 we see something else.

GoodFig goes here.
Figure 1. Caption stuff.

BadFig goes here.
Figure 2. Caption stuff.

Figure 1 is so much better than Figure 2.


I'm not asking for a program like EndNote that will update the numbering in real time or anything that complicated (though that would be really nice). Rather, I'm just talking about a macro that will delete the reference and labeling text, and number the figures once I'm ready to share the document with other people. I can do this with find and replace, but it becomes tedious for many figures. Also, I know you can do something like this with figure captions, but I'd rather not mess with creating figure captions in Word. Furthermore, this general algorithm can be modified for equation numbers, which would be nice. I'd greatly appreciate any advice anyone can provide. Thanks!

~Nick

macropod
03-11-2014, 09:00 PM
I'm not asking for a program like EndNote that will update the numbering in real time or anything that complicated (though that would be really nice). Rather, I'm just talking about a macro that will delete the reference and labeling text, and number the figures once I'm ready to share the document with other people. I can do this with find and replace, but it becomes tedious for many figures. Also, I know you can do something like this with figure captions, but I'd rather not mess with creating figure captions in Word.
Any solution that entails the auto-sequencing of the Figure numbers and synching their references will be doing essentially the same as Word already does with Figure captioning, so I don't see the sense in re-inventing the wheel. What's wrong with using the tools Word already gives you?

As for leaving adding the content until "I'm ready to share the document with other people", that's dumb - you should be implementing this as you go instead of trying to correct what you haven't done properly the first time. IMHO what you're asking for is for someone to develop a solution you can implement to compensate for not using Word properly in the first place.

nt3
03-12-2014, 06:47 AM
Any solution that entails the auto-sequencing of the Figure numbers and synching their references will be doing essentially the same as Word already does with Figure captioning, so I don't see the sense in re-inventing the wheel. What's wrong with using the tools Word already gives you?

As for leaving adding the content until "I'm ready to share the document with other people", that's dumb - you should be implementing this as you go instead of trying to correct what you haven't done properly the first time. IMHO what you're asking for is for someone to develop a solution you can implement to compensate for not using Word properly in the first place.



I appreciate your input. Maybe it would be easier to think of it in terms of equation numbering, which, to the best of my knowledge, Word does not facilitate. (If it does, I would greatly appreciate you directing me to a resource so I could learn how to do it.) So, suppose this was my document:


In Eq. /rE{BadEq} we can see such and such. However, in Figure /rE{GoodEq} we see something else.

(GoodEq goes here.) (/lE{GoodEq})

(BadEq goes here.) (lE{BadEq})

Eq. /rE{GoodEq} is so much better than Eq. /rE{BadEq}.


I would want this to be changed to the following after running the macro:


In Eq. 2 we can see such and such. However, in Figure 1 we see something else.

(GoodEq goes here.) (1)

(BadEq goes here.) (2)

Eq. 1 is so much better than Eq. 2.



I agree that it would be better to do this in real time. However, I don't know how to do that and I thought it would be easier (i.e. a shorter and simpler macro) to run the macro once I was ready to share the document. If it would be easier or sufficiently better to do it in real time, then I'd greatly appreciate advice on how to do that. Thanks!

~Nick

macropod
03-12-2014, 03:08 PM
I appreciate your input. Maybe it would be easier to think of it in terms of equation numbering, which, to the best of my knowledge, Word does not facilitate. (If it does, I would greatly appreciate you directing me to a resource so I could learn how to do it.)
...
I agree that it would be better to do this in real time. However, I don't know how to do that and I thought it would be easier (i.e. a shorter and simpler macro) to run the macro once I was ready to share the document. If it would be easier or sufficiently better to do it in real time, then I'd greatly appreciate advice on how to do that.
Both issues are easily resolved via References>Insert Caption and choosing Equation from the Equation, Figure or Table in the Labels dropdown. You can even add new labels! Then, to cross-reference a given caption, use Insert|Cross Reference and choose Equation from the Reference type dropdown. If you don't like Word's Caption Style (I don't), you can change it. Hint: unless you want the captioned content to adopt the Caption's paragraph Style, put the caption in a separate paragraph.

nt3
03-13-2014, 11:29 AM
Both issues are easily resolved via References>Insert Caption and choosing Equation from the Equation, Figure or Table in the Labels dropdown. You can even add new labels! Then, to cross-reference a given caption, use Insert|Cross Reference and choose Equation from the Reference type dropdown. If you don't like Word's Caption Style (I don't), you can change it. Hint: unless you want the captioned content to adopt the Caption's paragraph Style, put the caption in a separate paragraph.

Thank you again for that information. I was able to get things working reasonably well using the built in tools, as you suggested. As an aside, why isn't it an option to select only the number for reference in cross-reference|Insert referent to? That would make life much easier. Thanks again!

~Nick

macropod
03-13-2014, 01:52 PM
As an aside, why isn't it an option to select only the number for reference in cross-reference|Insert referent to? That would make life much easier.
Probably because it didn't occur to MS that people might want to do so. If you want just the number, select the cross-reference and press Shift-F9. You should see something like {REF _Ref382546659 \h}. Change this to {REF _Ref382546659 \# 0 \h} then press F9 to update the display.

nt3
03-17-2014, 10:03 AM
Probably because it didn't occur to MS that people might want to do so. If you want just the number, select the cross-reference and press Shift-F9. You should see something like {REF _Ref382546659 \h}. Change this to {REF _Ref382546659 \# 0 \h} then press F9 to update the display.

Thanks for that advice!

~Nick