R – Selecting and tagging specific formatting in word documents


being in need to export a DOC file to TXT and then reimport it without losing bold and underline formatting I'd need a macro to do that.

My idea is to select each group of words in bold (could be a sentence or a single word in sentence) and then write say <$> before it and <$$> after it. When back in word the reverse should happen, i.e. all text between <$> and <$$> back to bold. The same macro works for underline and bold+underline. I tried to export doc to html, then open in an html editor and save as txt saving only the bold and underline tags. Perfect, if not for the CR LF that the editor puts at the end end of each line…

TIA, my macro programming skills are short of basic…


Best Solution

Could you provide some example document for the original file and file you processed? If it is only about CR and LF, you can replace them via VBA:

textasstring = Replace$(textasstring, vbCrLf, "") textasstring = Replace$(textasstring, vbLf, "")

Another solution is to take an editor which is able to support extended search and replace including \r and \n like notepad++.

Related Question