There is no function built into Word that does what you want.
You will need to write a macro. That is
write a macro, not
record one.
"Header" or "heading?"
What is the difference between headings and headers?
I expect that you will get help with writing a macro here but you need to learn some concepts and vocabulary. Here are some starting places: