VBScript, Text to Clipboard to Paste in Any Field

假如想象 提交于 2021-02-10 12:52:08

问题


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


回答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.




回答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



回答3:


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


来源:https://stackoverflow.com/questions/28687675/vbscript-text-to-clipboard-to-paste-in-any-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!