How can I use Clipboard in vbscript? [duplicate]

You can do it with an html object to retrieve the contents of the clipboard:

' Get clipboard text
Set objHTML = CreateObject("htmlfile")
text = objHTML.ParentWindow.ClipboardData.GetData("text")

EDIT: I use this snippet to put text back on the clipboard, but it needs third party software; a standalone executable ‘clip.exe’ which can be found on Windows 2003 Server or just on the internet:

' Do something with the text
text = replace(text, "you ", "you and your dog ")

' Put it back to the clipboard
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("clip")

Set oIn = oExec.stdIn

oIn.WriteLine text
oIn.Close

(Yes, it is all a little bit hackerdyhack)

Leave a Comment