NOTE: For the un-Microsoft-initiated, you can make use of this even if you don't "have a copy" of Visual Basic. VB (actually a special flavor called VBA, "Visual Basic for Applications") is the scripting language for Microsoft Office. It's built in. If you have Word, you have it, so fear not.
Since a good deal of E2 users seem to do their noding in Microsoft
Word, or at least drop their nodes in there to use the spellchecker,
I thought I'd offer up this little utility. This is a Visual Basic macro
that inserts hardlinks in Word. Simply place the cursor inside a word
you want to hardlink, or select multiple words (you can do this by double-clicking-and-dragging
or Ctrl-Shift-ArrowKey), and then execute the macro. (I assign it to Alt-[
but use whatever works for you and your keyboard.) Whatever you selected
gets automagically enclosed in hardlink brackets.
I have found this to be a huge
timesaver for lengthy writeups. I typically
type out a whole node, then insert the
html and hardlinks last. A macro
bound to a key is a tremendously
speedy way of hardlinking. As a special
bonus, observe that the last two lines of the
subroutine are
where
the action is, and nothing says that they can't surround your selection
of choice with, e.g., <p> and </p> or <i> and </i>.
Make a few flavors of this function bound to different keys, and you can
italicize and paragraph-ize with
ease.
If you need instructions putting a macro into Word, they are at the
bottom. Happy hardlinking.
Sub AddHardLinkBrackets()
'Macro to add hard link brackets around a word or selection
'
'Select current word the cursor is in,
'if there is currently no selection
If Selection.Range.Start = Selection.Range.End Then
Selection.MoveLeft Unit:=wdWord, Count:=1
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
End If
'Eliminate blank spaces at end of selection, if any
'(Word pads selections with spaces after the word automatically)
While Selection.Range.Characters.Last = " "
Selection.SetRange Start:=Selection.Range.Start, _
End:=Selection.Range.End - 1
Wend
'Finally, insert the hardlink brackets
Selection.InsertBefore "["
Selection.InsertAfter "]"
End Sub
Whatever you think about VB/VBA (and I'm not a raging fan, mind you), you gotta admit that the above is fairly compact, readable and powerful as things go. Office is much better with it than without (and it's a lifesaver in Excel). If Microsoft's documentation didn't totally suck ass it would even be easy to figure out how to do things like this. Most of the time I have to wander blindly through the object hierarchy until I trip over what I need. Sigh. But it works!
Steps for inserting this as a Word macro (tested in Word 97 on Win NT4, your mileage may vary):
- Navigate down the menu: Tools, Macro, Record New Macro. Give your
macro a meaningful name, like "AddHardLinkBrackets", and hit
the "Keyboard" button to bind it to a key.
- This will bring you to a "Customize Keyboard" screen. Now
you type the key combo you want to use to run the macro. I use Alt-[
because it's fast and not reserved by Word, but whatever makes you happy.
Hit the Assign button, and then the Close button.
- Now a teensy little recorder window pops up. Word is now taking down
what we do, but we're not going to record anything. We want to stop recording
immediately, so hit the square "stop recording" button.
- When you hit stop, Word will give you no feedback whatsoever. How typical.
But rest assured your macro has been created. Go back to menu Tools,
Macro, Macros (or just hit Alt-F8) and find your new macro in the list.
Select it from the list, and hit the Edit button.
- Now you will be catapulted into the VB edit environment. You should
have a macro in front of you that looks something like this (the single-quote
lines are comments):
Sub AddHardLinkBrackets()
'
' AddHardLinkBrackets Macro
' Macro recorded 09/20/00 by sockpuppet
'
End Sub
- Good. Now delete that entirely and paste in the big program at
the beginning of the node.
- You are done! Flip back to Word, give it a go, and start hardlinking
up a storm. If you've accepted all the defaults along the way other than
what is outlined above, the macro will get stored in your "template"
doc and be available whenever you use Word.
Exercise for the reader: it's also easy to see how a version
of this could be created to deal with plurals, ie: transform the
word "heuristics" into [heuristic|heuristics] for purposes of plural-safe
hardlinking. You wouldn't want to use it everywhere, of course, since
lots of words end in 's' which are not plural. But it could be handy.