This is an old one, but still a good one.
Want to do something programmatically in Word/Excel etc. and don't know how to? Simply hit Tools/Macro/Record to start recording a new macro. Perform the action through the UI, and stop the recording. Then you have sample VBA code in the macro to get you going.