VBScript, Text to Clipboard to Paste in Any Field

22,567

Solution 1

Here's a script for reading the clipboard, Just change it to copy.

Sub Clip
    Set ie = CreateObject("InternetExplorer.Application") 
    ie.Visible = 0
    ie.Navigate2 FilterPath & "Filter.html"
    Do 
        wscript.sleep 100
    Loop until ie.document.readystate = "complete"  
    txt=ie.document.parentwindow.clipboardData.GetData("TEXT")
    ie.quit
    If IsNull(txt) = true then 
        outp.writeline "No text on clipboard"
    else
        outp.writeline txt
    End If
End Sub

When using IE as a object you must navigate to a local file to turn off security.

A shortcut on the Desktop or on the Start menu can have a hotkey assigned in it's properties. This will start the shortcut, or if already started, switch to that window.

Solution 2

To set the value of the clipboard, you could use this Sub:

Sub SetClipboard(val) 
    Set oExcel = CreateObject("Excel.Application")
    Set book = oExcel.Workbooks.Add()
    Set sheet = book.Sheets("Sheet1")
    sheet.Cells(1.1).Value = val
    sheet.Cells(1,1).Copy
    book.Close False
    Set oExcel = Nothing
End Sub

To get value of the clipboard, you could use this Sub:

Sub GetClipboard() 
    Set oExcel = CreateObject("Excel.Application")
    Set book = oExcel.Workbooks.Add()
    Set sheet = book.Sheets("Sheet1")
    sheet.Paste
    ValueInClipboard = sheet.Cells(1.1).Value
    book.Close False
    Set oExcel = Nothing
    WScript.StdOut.Write ValueInClipboard
End Sub
Share:
22,567
Lowell
Author by

Lowell

Updated on May 31, 2020

Comments

  • Lowell
    Lowell almost 4 years

    I have put together a script that will copy my desired text into my clipboard so I can paste content in any text field.

    Dim string 
    String = "This Is A script that allows me to copy text contained withing these quotes directly into my clipboard. Which yes is plenty fast as it is when compared to finding file, opening file, selecting desired content, copy content, and select location to paste content."
    Set WshShell = WScript.CreateObject("WScript.Shell") 
    WshShell.Run "cmd.exe /c echo " & String & " | clip", 0, TRUE
    

    Current steps required is

    1. run script
    2. navigate to desired location
    3. paste content.

    I am trying to make it so that I can use a hotkey at desired location 1. Ctrl + Alt + F1 (Or any combo) to get Text to Clipboard to Paste

  • Zimba
    Zimba almost 4 years
    and for those who don't have MS Excel (Office)?