Jump to content

Change font and text size in ClipPut

Recommended Posts

Hi i'm trying to create a ClipPut with differents font size and font and then paste it into word document.

I know in Word document, i can send("^+P") and change the font size, but it's not then best way to do if i have to change the font and size many time in the document.

    WinActivate("ReportTemplate.doc [Compatibility Mode] - Word")
    WinWaitActive("ReportTemplate.doc [Compatibility Mode] - Word")
    Sleep (1000)
    ClipPut("Underline Size 16: " & "Bold size 12" & "Normcal size 11")

Any idea?



Link to post
Share on other sites

this is a logic of _Clipput  , you can start  at here   , probably you must play with some  DLL , sorry i am not much experience about  this but  if you know ,you will try

; #FUNCTION# ====================================================================================================================
; Author ........: Piccaso (Florian Fida)
; Modified.......: Gary Frost (gafrost)
; ===============================================================================================================================
Func _ClipPutFile($sFilePath, $sDelimiter = "|")
    Local Const $GMEM_MOVEABLE = 0x0002, $CF_HDROP = 15

    $sFilePath &= $sDelimiter & $sDelimiter
    Local $nGlobMemSize = 2 * (StringLen($sFilePath) + 20)

    Local $aResult = DllCall("user32.dll", "bool", "OpenClipboard", "hwnd", 0)
    If @error Or $aResult[0] = 0 Then Return SetError(1, _WinAPI_GetLastError(), False)
    Local $iError = 0, $iLastError = 0
    $aResult = DllCall("user32.dll", "bool", "EmptyClipboard")
    If @error Or Not $aResult[0] Then
        $iError = 2
        $iLastError = _WinAPI_GetLastError()
        $aResult = DllCall("kernel32.dll", "handle", "GlobalAlloc", "uint", $GMEM_MOVEABLE, "ulong_ptr", $nGlobMemSize)
        If @error Or Not $aResult[0] Then
            $iError = 3
            $iLastError = _WinAPI_GetLastError()
            Local $hGlobal = $aResult[0]
            $aResult = DllCall("kernel32.dll", "ptr", "GlobalLock", "handle", $hGlobal)
            If @error Or Not $aResult[0] Then
                $iError = 4
                $iLastError = _WinAPI_GetLastError()
                Local $hLock = $aResult[0]
                Local $tDROPFILES = DllStructCreate("dword pFiles;" & $tagPOINT & ";bool fNC;bool fWide;wchar[" & StringLen($sFilePath) + 1 & "]", $hLock)
                If @error Then Return SetError(5, 6, False)

                Local $tStruct = DllStructCreate("dword;long;long;bool;bool")

                DllStructSetData($tDROPFILES, "pFiles", DllStructGetSize($tStruct))
                DllStructSetData($tDROPFILES, "X", 0)
                DllStructSetData($tDROPFILES, "Y", 0)
                DllStructSetData($tDROPFILES, "fNC", 0)
                DllStructSetData($tDROPFILES, "fWide", 1)
                DllStructSetData($tDROPFILES, 6, $sFilePath)
                For $i = 1 To StringLen($sFilePath)
                    If DllStructGetData($tDROPFILES, 6, $i) = $sDelimiter Then DllStructSetData($tDROPFILES, 6, Chr(0), $i)

                $aResult = DllCall("user32.dll", "handle", "SetClipboardData", "uint", $CF_HDROP, "handle", $hGlobal)
                If @error Or Not $aResult[0] Then
                    $iError = 6
                    $iLastError = _WinAPI_GetLastError()

                $aResult = DllCall("kernel32.dll", "bool", "GlobalUnlock", "handle", $hGlobal)
                If (@error Or Not $aResult[0]) And Not $iError And _WinAPI_GetLastError() Then
                    $iError = 8
                    $iLastError = _WinAPI_GetLastError()
            $aResult = DllCall("kernel32.dll", "ptr", "GlobalFree", "handle", $hGlobal)
            If (@error Or $aResult[0]) And Not $iError Then
                $iError = 9
                $iLastError = _WinAPI_GetLastError()
    $aResult = DllCall("user32.dll", "bool", "CloseClipboard")
    If (@error Or Not $aResult[0]) And Not $iError Then Return SetError(7, _WinAPI_GetLastError(), False)
    If $iError Then Return SetError($iError, $iLastError, False)
    Return True
EndFunc   ;==>_ClipPutFile


Link to post
Share on other sites

In fact i have a script that catching different string from fields from web page, and then i want to paste these variables into a word document and some variables are Bold, and others are normals

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By diff
      still learning and trying to understand AutoIT but having problem in filling my PDF file.
      So my code looks like similar to this:
      Global $1 = "text text 44444444" Global $2 = "texting2 texting2" Global $3 = "newtext3 next3" ShellExecute ("C:\Users\XXX\Desktop\myPDF.pdf") WinWaitActive("MyPDF.pdf - Adobe Acrobat Reader DC") Send ("{TAB}") ClipPut($1) Send ("^v") Send ("{TAB 3}") ClipPut($2) Send("^v") Send ("{TAB}") ClipPut($3) Send("^v") So its fill my PDF form, the first field looks good, the code add the text text 4444, then second should be $2 with texting2 texting2 but for some reason the code uses for second and third field after TAB only variable $3.
      So, I receive in $2 and $3 for some reason same newtext3 next3 in both, why its skipping the variable $2? Maybe there also much better solution for instant text? Because Send writes with delay by letters which I don't like.
    • By cdeb
      How can you select the specific style of a font with multiple * .otf files?
      The font in question has several files:
      Thin Thin Italic Extra-Light Extra-Light Italic Light Light Italic Regular Regular Italic Medium Medium Italic Semi-Bold Semi-Bold Italic Bold Bold Italic Extra-Bold Extra-Bold Italic Black Black Italic But after doing several tests I can recall the font like this, without being able to specify the precise style:
      Local $hFamily = _GDIPlus_FontFamilyCreate("Poppins") ; Local $hFont = _GDIPlus_FontCreate($hFamily, 95, 1+2, 3) ; Example I cannot therefore select "Poppins Black Italic"
      but only "Poppins" 
      Thank you

    • By SkysLastChance
      What am I doing wrong here. 
      I am trying to get a list of names in the clip that look like
      I have tried
      ClipPut("Bob" & @CRLF & "Greg" & @CRLF & "James" & @CRLF & "Kevin" & @CRLF & "Tim" & @CRLF & "Kelly" & @CRLF & _ "Susan"_& @CRLF & "Bill" & @CRLF & "Maggie" & @CRLF & "Amanda" & @CRLF & "Matt" & @CRLF & "Robert" & @CRLF & "Sara" & @CRLF & _ "Zach" & @CRLF) and
      ClipPut("Bob" & @CRLF & "Greg" & @CRLF & "James" & @CRLF & "Kevin" & @CRLF & "Tim" & @CRLF & "Kelly" & @CRLF & _ & "Susan"_& @CRLF & "Bill" & @CRLF & "Maggie" & @CRLF & "Amanda" & @CRLF & "Matt" & @CRLF & "Robert" & @CRLF & "Sara" & @CRLF & _ & "Zach" & @CRLF)  
    • By rudi
      from other postings here as a start I'm quite Close to my Goal of putting formatted text to the clipboard:
      #include-once #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> Global $g_idLblMsg, $g_hRichEdit Example("The first text will be formatted ""as is""" & @CRLF & _ "(Default Font and font size)", "This text is formatted differently") MsgBox(0, "Rich Text copied", "Formatted Text put to clipboard") Func Example($TextDefault, $TextCourier) Local $hGui, $iMsg, $idBtnNext, $iStep = 0 $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 320, 350, -1, -1) $g_hRichEdit = _GUICtrlRichEdit_Create($hGui, $TextDefault, 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $g_idLblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60) GUISetState(@SW_SHOW) _GUICtrlRichEdit_SetSel($g_hRichEdit, -1, -1) ; set selection behind last CHAR in RTF_EDIT _GUICtrlRichEdit_SetFont($g_hRichEdit, 8, "Courier New") ; change font to 8pt, Courier New _GUICtrlRichEdit_AppendText($g_hRichEdit, @CRLF & $TextCourier) _GUICtrlRichEdit_SetSel($g_hRichEdit, 0, -1) ; select all the content of the RTF_EDIT _GUICtrlRichEdit_Copy($g_hRichEdit) ; put the selection to the clipboard EndFunc ;==>Example  
      Finally the clipboard content has to hold pre-formatted data to be pasted into an email body. for the 2nd part I'd like to add a frame around the text, like I did manually before taking this screenshot.

      Any suggestions, or maybe some absolutely different Approach?
      CU, Rudi.
    • By XinYoung
      Hello all!   I'm stuck at a seemingly simple part of my script. Using IE, I'm filling out a web form that involves clicking a "Browse" button and selecting a file. Once the file explorer dialog opens, however, I am unable to control it.
      I have a string, which is the name of the file I want, and I'm trying to insert it into the 'File name:' text box in the dialog (which already has focus), but it doesn't get inserted. I've tried ClipPut and Send. 

      What's even more concerning is, when I close the dialog, the string is then pasted into the very next window that has focus, which is often SciTE. It's like that Browse's file open dialog halts all processes. Once it's closed, the script continues.
      ;~ Open a IE window and navigate to the login page. Global $oIE = _IECreate($urlBBLogin) _IELoadWait($oIE) ;~ Recognize the form on this page (login input boxes). Local $oForm = _IEFormGetObjByName($oIE, "login") Local $oTextLogin = _IEFormElementGetObjByName($oForm, "user_id") Local $oTextPass = _IEFormElementGetObjByName($oForm, "password") ;~ Enter the Automation user credentials into the form. _IEFormElementSetValue($oTextLogin, $bbUsername) _IEFormElementSetValue($oTextPass, $bbPassword) ;~ Click the Login button. _IEFormSubmit($oForm) _IELoadWait($oIE) ;~ Navigate to the feedfile upload page. _IENavigate($oIE, $urlUpload) _IELoadWait($oIE) ;~ Click the Browse button Local $Browse = _IEGetObjById($oIE, "feedFile_chooseLocalFile") _IEAction($Browse, "Click") Local $Browse = WinWait("Choose File to Upload") ;~ Open the file we created. WinActivate($Browse) Send($finalFile) Has anyone else experienced this problem? Any ideas to get around it? Am I approaching this the wrong way?
      Any support is greatly appreciated.
      Thank you.
  • Create New...