Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

emmulating the paste command with VB script?

543 views
Skip to first unread message

Russ

unread,
May 7, 2003, 3:03:19 PM5/7/03
to
How can I program a vbscript to paste text (ctrl-V)? Say for example you
want to run a script that would dump whatever is on the clipboard into a
text file or a user clicks copy on a file and then runs a script that will
paste it in a specific location?


Joe Earnest

unread,
May 7, 2003, 3:21:16 PM5/7/03
to
Hi,

"Russ" <ru...@acordiamn.com> wrote in message
news:eBEzTtMF...@TK2MSFTNGP12.phx.gbl...

If you can install a third-party ActiveX, check out AutoItX, freeware
by Hiddensoft. It is a good overall addition, has some significant
improvements over straight VBS and has more articulate and reliable
window management, sendkey data, universal shutdowns, and simple
clipboard methods and functions.

http://www.hiddensoft.com/AutoIt/

If you want straight VBS ...

Here is a Tom Lavedas - Walter Zachary workaround to read the
clipboard content with the HTMLFile object:

Set oHtml = CreateObject("htmlfile")
sClipText = oHtml.ParentWindow.ClipboardData.GetData("text")
WScript.Echo sClipText

However, 'htmlfile' only works for reading the clipboard.
For writing to the clipboard, the standard trick is to
write to notepad or a text box and transfer. See ...

http://www.borncity.com/WSHBazaar/News7.htm

There's also a script posted there on using the HTML
ExecCommand method for trnsfer.

For writing, you can also use InternetExplorer.Application
(this is untested air code, so test for errors; it's based on
jscript code posted by Christoph):

Set oIE= CreateObject("InternetExplorer.Application")
With oIE
Do: .Navigate "about:clipdata": Loop While .busy
Set oData= .Document.ParentWindow.ClipboardData
End With
oData.SetData("Text", "your text string")
sText= oData.getData("Text")
oIE.Quit
WScript.Echo sText

Per Torgeir Bakken, these methods can result in error messages.
To them, change the IE settings:
Tools \ Internet Options \ Security tab \ Internet \
"Drag and drop or copy and paste files"
from "Prompt" to "Enable" .

or add about:blank and about:clipdata to the "Trusted sites"
security zone if trusted sites are allowed to copy and paste.

Joe Earnest

0 new messages