I would like to change formatting of text in a Clipboard and paste it to MS Word file Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
NagaSuka
Posts: 15
Joined: 15 Oct 2017, 13:09

I would like to change formatting of text in a Clipboard and paste it to MS Word file

15 Oct 2017, 13:40

Hey, I have a simple script which makes a copy of a text from a browser and pastes to MSWord file automatically by keyboard shortcuts. I would like to make special formatting of this text - to have it in white font (to attain hidden text effect).

In other words: I would like to have a script which.

1) makes a copy of a text to Clipboard,
2) change a font to white
3) paste to file which I want.

Point 2 is missing.
NagaSuka
Posts: 15
Joined: 15 Oct 2017, 13:09

Re: I would like to change formatting of text in a Clipboard and paste it to MS Word file

15 Oct 2017, 17:48

Where do you see a solution there? Surrounding in my Word file is not white, so MS options will not work. I want to copy black text to file with black text, but the copied text should be changed on the fly to white before pasting.

If it's possible, please for a line of code with such change on the fly.
teadrinker
Posts: 4331
Joined: 29 Mar 2015, 09:41
Contact:

Re: I would like to change formatting of text in a Clipboard and paste it to MS Word file

15 Oct 2017, 18:31

Hi, NagaSuka,

What do you mean by "paste to file"? Do you mean "add to the end of the file"? Or you mean "paste to MS Word Editor window to the caret position"?
NagaSuka
Posts: 15
Joined: 15 Oct 2017, 13:09

Re: I would like to change formatting of text in a Clipboard and paste it to MS Word file

15 Oct 2017, 19:29

Hi Teadrinker,

I mean caret position.

I read some texts in Word file, look up in the dictionary for important terms and would like to paste a translation in white font colour to have it a little hidden in the main text. Later I will make revision if I memorised this important terms.
teadrinker
Posts: 4331
Joined: 29 Mar 2015, 09:41
Contact:

Re: I would like to change formatting of text in a Clipboard and paste it to MS Word file  Topic is solved

16 Oct 2017, 04:03

Try:

Code: Select all

$F10::
   PutSelectedTextInClipboard()
   PasteFormattedText( GetWord() ).Font.ColorIndex := 8   ; wdWhite := 8
   Return
   
PutSelectedTextInClipboard()  {
   tempClip := ClipboardAll
   Clipboard := ""
   SendInput, ^{sc2E}  ; Ctrl + C
   ClipWait, .5
   if ErrorLevel  {
      Clipboard := tempClip
      MsgBox, Filed to get text!
   }
}

PasteFormattedText(oWord)  {
   rng := oWord.Selection.Range
   rng.Paste
   Return rng
}

GetWord()  {
   if !hwnd := WinActive("ahk_class OpusApp")
      hwnd := WinExist("ahk_class OpusApp")
   ControlGet, ControlHwnd, Hwnd,, _WwG1, ahk_id %hwnd%
   Return AccObjectFromWindow(ControlHwnd, -16).Application
}

AccObjectFromWindow(hWnd, idObject = 0)
{
   static IID_IDispatch   := "{00020400-0000-0000-C000-000000000046}"
        , IID_IAccessible := "{618736e0-3c3d-11cf-810c-00aa00389b71}"
        , OBJID_NATIVEOM := 0xFFFFFFF0, VT_DISPATCH := 9, h := DllCall("LoadLibrary", Str, "oleacc", Ptr)
        
   VarSetCapacity(IID, 16), idObject &= 0xFFFFFFFF
   DllCall("ole32\CLSIDFromString", Str, idObject = OBJID_NATIVEOM ? IID_IDispatch : IID_IAccessible, Ptr, &IID)
   if DllCall("oleacc\AccessibleObjectFromWindow", Ptr, hWnd, UInt, idObject, Ptr, &IID, PtrP, pAcc) = 0
      Return ComObjEnwrap(VT_DISPATCH, pAcc, 1)
}
Open MS Word editor with your file, set the caret to the place you need, launch my script, then select the text you want to paste and press F10.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, Frogrammer, Google [Bot], mcd and 191 guests