One reader recently took up my challenge to not run screaming from macros … and was a little disappointed in the results.
A macro that only runs until you log off. Well, that’s a puzzler.
As I told him in our email exchange, I’ve noticed that in Word 2010, macros are sometimes spotty in picking up settings from actions you take in the Ribbon. (It used to work fine — not sure what’s changed.) I myself had a similar problem with a macro I tried to do for a watermark.
I suspected he was attempting to embed the page number command using Word’s Insert Page Number command from the Header/Footer Tools contextual ribbon menu:
The problem there is the contextual part. I think the macro was freaking out because it didn’t find the Header/Footer Tools menu from which to draw the Insert Page Number command, so it scrambled. (The whole “macro disappears when I log out” thing? I got no clue.)
So I suggested he program the “Insert Page Number” thing into his macro from the Quick Parts menu instead:
For you code jockeys out there, here’s how that works out:
' test Macro
Selection.TypeText Text:="Page "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"PAGE \* Arabic ", PreserveFormatting:=True
Just what I like to hear!
Got a question of your own? Ask it via my Ask the Guru page!