Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clearing the clipboard using VBScript

How can the clipboard be cleared using VBScript on Win32?

like image 729
user288181 Avatar asked Mar 07 '10 11:03

user288181


1 Answers

It can not be done directly, but you can let an application do the work. This will clear the clipboard, using the command-line tool clip:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo. >NUL  | clip", 0, True

Another way is to use applications that have a COM interface and that can manipulate the clipboard. E.g. Microsoft Word and Internet Explorer.

This will work, using Internet Explorer, but it may throw a user dialog:

Set slaveApplication = CreateObject("InternetExplorer.Application")
slaveApplication.Navigate("about:blank")
slaveApplication.document.parentwindow.clipboardData.SetData "text", ""
slaveApplication.Quit
like image 162
Peter Mortensen Avatar answered Nov 24 '22 23:11

Peter Mortensen