cpht
cpht

Reputation: 77

VBScript, Text to Clipboard to Paste in Any Field

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

Upvotes: 2

Views: 28699

Answers (3)

Zimba
Zimba

Reputation: 3691

To get text from clipboard:

' Use the HTML parser to get clipboard text
Dim x : x = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("text")

WScript.Echo x

To write contents to file:

Dim fileObj : Set fileObj = CreateObject("Scripting.FileSystemObject").CreateTextFile("clipboard.txt")
fileObj.Write(x)
fileObj.Close

Upvotes: 0

Srinath Jackie
Srinath Jackie

Reputation: 36

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

Upvotes: 1

Serenity
Serenity

Reputation: 46

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.

Upvotes: 3

Related Questions