VBScript,剪贴板文本粘贴到任何字段

时间:2015-02-24 03:30:16

标签: vbscript clipboard copy-paste

我已经整理了一个脚本,将我想要的文本复制到剪贴板中,这样我就可以在任何文本字段中粘贴内容。

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

当前所需的步骤是

  1. 运行脚本
  2. 导航至所需位置
  3. 粘贴内容。
  4. 我正在努力使它能够在所需位置使用热键 1. Ctrl + Alt + F1(或任何组合)将Text to Clipboard粘贴到

3 个答案:

答案 0 :(得分:2)

这是一个用于阅读剪贴板的脚本,只需将其更改即可复制。

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

使用IE作为对象时,必须导航到本地文件才能关闭安全性。

桌面或“开始”菜单上的快捷方式可以在其属性中指定热键。这将启动快捷方式,或者如果已经启动,则切换到该窗口。

答案 1 :(得分:0)

要设置剪贴板的值,您可以使用此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

要获取剪贴板的值,您可以使用此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

答案 2 :(得分:0)

要从剪贴板获取文本:

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

WScript.Echo x

要将内容写入文件:

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