One way, not completely automatic, is as follows: go through the document, click in a paragraph intended as a heading, note the formatting details, then open the Find/Replace dialog box (Ctrl+H), tick Other options, click Format, enter some of the formatting details of that paragraph, click Find all, close the dialog box. All text with that formatting will now be selected. Press Ctrl+M to remove all direct formatting from the selection(1), then apply the paragraph style that you want to use for those headings. Now move to the next heading paragraph not yet dealt with and repeat that procedure. Finally deal with the body text. It’s a good idea to set a font for the styles that isn’t yet used in the document while you are cleaning it up, so that any remaining text with direct formatting will be easily noticed.
I doubt that writing a macro is worth the effort - development and debugging takes a lot of time.
(1) Don’t use Ctrl+M for large blocks of text if there’s also formatting like italics or boldface of single words, because that will be lost. You can replace such formatting by character styles though - search for text in italics, then apply a character style, maybe you should make one called italics just for that purpose. Once that’s done, you can safely remove direct formatting.