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

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Can I modify the text formatting before paste?

Post by HiSoKa » 27 Oct 2021, 14:33

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 557 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 557 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?

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Can I modify the text formatting before paste?

Post by mikeyww » 28 Oct 2021, 06:49

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

User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Re: Can I modify the text formatting before paste?

Post by HiSoKa » 28 Oct 2021, 08:41

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

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

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

Post by mikeyww » 28 Oct 2021, 08:56

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

User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Re: Can I modify the text formatting before paste?

Post by HiSoKa » 28 Oct 2021, 09:09

This is very useful,
Thank you very much again

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Can I modify the text formatting before paste?

Post by mikeyww » 28 Oct 2021, 09:58

Add to the end, to close the process.

Code: Select all

oWord.Quit(wdDoNotSaveChanges := 0)

Post Reply

Return to “Ask for Help (v1)”