Page 1 of 1

Can I modify the text formatting before paste?

Posted: 27 Oct 2021, 14:33
by HiSoKa
I have a text when I copy and paste it to another program that causes me an error,
Because of copying its formatting or perhaps the numbers and spaces which at the beginning of the lines
ِAs shown below (This is the text that I try to copy),
1.png
1.png (12.47 KiB) Viewed 602 times
I don't want to completely delete the format, I just want to keep the bold font (Because it does not cause errors when I paste it into the program),
I want when i copy text to ignore any symbol other than English letters like this too,
2.png
2.png (3.63 KiB) Viewed 602 times
Note:I can't control them, when I copy the text above then paste it in the program,
They are automatically pasted even if I don't selected them.

My question is can I solve this problem with keeping the bold text,
Is this possible or should I delete the text formatting completely?

Re: Can I modify the text formatting before paste?

Posted: 28 Oct 2021, 06:49
by mikeyww
This is close, though the font was altered for some reason.

Code: Select all

F3::
oWord := ComObjActive("Word.Application"), active := oWord.ActiveDocument.Range
active.Paste
active.ListFormat.RemoveNumbers
active.Copy
Return

Re: Can I modify the text formatting before paste?

Posted: 28 Oct 2021, 08:41
by HiSoKa
Great, thanks a lot @mikeyww , This is what I've been looking for for a long time.
But another question please,
Is it possible to execute this code without opening Microsoft Word.

Code: Select all

F3::
send, ^c
oWord := ComObjActive("Word.Application"), active := oWord.ActiveDocument.Range
active.Paste
active.ListFormat.RemoveNumbers
active.Copy
Return

Esc::ExitApp

Re: Can I modify the text formatting before paste?  Topic is solved

Posted: 28 Oct 2021, 08:56
by mikeyww

Code: Select all

F3::
Gui, New
Gui, Font, s12 w500
Gui, Color, F8DC75
Gui, Add, Text, w320 Center, Please wait....
Gui, Show,, Working
oWord := ComObjCreate("Word.Application"), oWord.Visible := False, oWord.Documents.Add
active := oWord.ActiveDocument.Range, active.Paste
Sleep, 100
active.ListFormat.RemoveNumbers
Clipboard := "", active.Copy
Gui, Destroy
ClipWait, 0
If ErrorLevel
 MsgBox, 48, Error, An error occurred while waiting for the clipboard.
Return

Re: Can I modify the text formatting before paste?

Posted: 28 Oct 2021, 09:09
by HiSoKa
This is very useful,
Thank you very much again

Re: Can I modify the text formatting before paste?

Posted: 28 Oct 2021, 09:58
by mikeyww
Add to the end, to close the process.

Code: Select all

oWord.Quit(wdDoNotSaveChanges := 0)