Paste RTF text to OneNote while retaining formatting

Post your working scripts, libraries and tools for AHK v1.1 and older
doobie34
Posts: 1
Joined: 13 Jun 2017, 09:07

Paste RTF text to OneNote while retaining formatting

13 Jun 2017, 22:48

When you copy code from IDE's such as Eclipse the format of copied text is RTF. This is not supported by OneNote. So, only plain text is copied without formatting.

But, Microsoft Word supports RTF. If you copy the code to RTF the formatting is retained and the text is converted to HTML format. Now if you copy this text from Word back to OneNote, the formatting is retained because now it's HTML and not RTF.

So, I wrote this little script that does this.

I'm new to AHK. So, there might be better solutions to this. But so far I'm satisfied with the outcome. I just posted in case someone else might find it useful.

Code: Select all

;copy RTF text from IDE and convert to HTML using Word
convert_rtf_to_html(){
	send, ^c	;copy text from IDE
	openWord()	;open new word doc or go to currently opened word doc
	sleep, 300	
	send, ^v	;paste text to word
	sleep, 300
	send, ^a	;select all text
	sleep, 200
	send, ^x	;cut all text
	sleep, 200
	winactivate ahk_exe onenote.exe	;go to oneNote window
	return	
	
}


;open new word doc or go to currently opened word doc
openWord(){
	IfWinExist ahk_exe winword.exe			;if word is open go to word window
		winactivate ahk_exe winword.exe
	else{									;;if word is not open, word program
		run, "<<address of word>>\winword.exe"
		sleep, 400							;; wait for intro menu to load
		Send,{Enter}						;; to get blank page
	}
	return

}

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: ConnorMcLoud and 153 guests