Ask:
Hey, scripting guy!. Is there a way to copy the script output to the clipboard?
--ZW, Marseilles, France
For:
Hello, ZW. If you don't mind using some crazy workaround, it's pretty easy to actually copy the script output to the Clipboard. First, you need to construct a string that contains the desired output. Then, create an instance of Internet Explorer and open a blank page in it. Next, take advantage of the built-in features of the Internet Explorer object model to copy the string to the Clipboard, and in particular, you can use the Clipboarddata.setdata method to implement this technique. The sample script that copies some data to the Clipboard is as follows:
Copy Code code as follows:
Strcopy = "This text has been copied to the Clipboard."
Set objIE = CreateObject ("Internetexplorer.application")
Objie.navigate ("About:blank")
ObjIE.document.parentwindow.clipboardData.SetData "Text", strcopy
Objie.quit
Run the script, then open Notepad, and then click Paste, and you should see the copied string.
By the way, all of this is happening behind the scenes, and Internet Explorer doesn't really appear on the screen. This is because, by default, any instance of IE created by scripting is hidden at run time unless you use the following statement to display it:
Objie.visible = True
For more information about Clipboarddata.setdata, see the DHTML reference documentation on MSDN.