06 May 2009

Put figures etc. in MS Word without the "Figure" tag

One of the annoying things (at least for me) about Microsoft Word is that it wants all your figure numbers to have "Figure" prepended to them. It's all great if you always say "Figure 1" or "Figure 2" but it doesn't work if you like to say things such as "As we see in Figures 1 & 2" and not "As we see in Figure 1 and Figure 2." Furthermore, Word doesn't work well with things such as "Figure 4.12" or, my favorite, having Figure 1 followed by Example 2 followed by Table 3 -- I'm big into continuous numbering.

So here's what I finally came up with as a solution. Type whatever preface you want to appear in the caption of the document ("Figure ") and then run this macro and give your figure a short name with no spaces ("voiceRangesDunstaple" for instance), then two numbers will appear. Leave the first alone; It'll put a number after "Figure" ("Figure 12" for instance). Copy and cut the second number and then paste it in your text somewhere -- it's the reference number to the figure ("See figure 12" -- I like lowercase figure references). You can paste this number multiple places if you need multiple references. And a quick "Ctrl-A, F9" will update all the tables.

You'll need to give this macro a keyboard shortcut if you use it often.

Sub MakeFieldCrossRef()
' Macro recorded 3/25/2006 by Myke
Dim Message, Title, Default, macroName
Message = "Enter a short, unique name for the Xref (no spaces!)"
Title = "Create Crossref"
Default = ""
macroName = InputBox(Message, Title, Default)
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"AUTONUMLGL \e", PreserveFormatting:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:=macroName
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.InsertCrossReference ReferenceType:="Bookmark", ReferenceKind:= _
wdContentText, ReferenceItem:=macroName, InsertAsHyperlink:=False, _
Call UpdateAllDocFields
End Sub

No comments: