Write Clipboard Data to a Text file

Posted on 2004-11-18
Last Modified: 2013-11-25
Here is what I'm looking to do.

1) Copy A field of text to the clipboard(I can do that using SendKeys)
2) Write what I just copied to a Text File (No clue how)
3) Move to a new field and copy that to the clipboard (Again using SendKeys)
3) Copy that field of text to a new line in the same text file (No Clue)

I am hoping I can use a VBScript to output the clipboard to the text file so I can just call that script from a dos batch file, which is what I use to fire off the send keys script. Thanks is advance!!
Question by:Cannibaltrout
    LVL 10

    Accepted Solution


    i just got this article ... read it and give a try...

    Hope It will help you..


    Hello Clipboard, WSH is calling you
    Many scripters wish to interact with the clipboard. Although WSH doesn't provide methods to do that, you can use a few tricks. Let's go step by step.

    The most efficient way will be to write an ActiveX control that provides you with methods allowing you to access Windows clipboard. I wrote such a control and shipped it with the MS Press title Inside Windows Script Host, 2. Ausgabe (and there are also plans that my upcoming English MS Press title Advanced Development with Microsoft Windows Script Host 2.0 will contain this control). But till now I'm not ready to release this stuff in the WSH Bazaar (because the description is still in German). That's odd, but fortunately there are a few way to overcome this situation.

    Well, maybe you intend to control two applications using WSH, and your script need to force one program to transfer data to the other. In this case you can force the application to copy data to clipboard and paste it into the document area of the other program. This will be used. The script launches Notepad and Calc, forces Calc to evaluate an expression and transfer the result to Notepad.

    ' File:   AppActivateWSH2.vbs (WSH 2.0 VBScript sample)  
    ' Author: (c) G. Born
    ' Launch Calc and Notepad, use AppActivate to
    ' switch between applications. Transfers data
    ' between Calc and Notepad using Clipboard (controlled
    ' by SendKeys.
    ' Attention: The script requires WSH 2.0 !!!
    Option Explicit

    ' Define the title strings of the application windows
    ' Use the title's begin or end, if a file name changes
    ' Important: strings depend on the localized Windows version
    Const Edit_Title = "Notepad"          ' window title
    Const Calc_Title = "Calculator"        ' window title

    DIM Wsh

    ' Create the Shell object, required for Run and AppActivate
    Set Wsh = WScript.CreateObject("WScript.Shell")

    ' we try to launch two applications - to assure that the
    ' last application receives the focus, we delay the script
    Wsh.Run "Calc.exe",1     ' launch Windows calculator
    WScript.Sleep 300        ' delay, till calc gets the focus
    Wsh.Run "Notepad.exe",1  ' launch Windows editor Notepad
    WScript.Sleep 300        ' delay, till notepad gets the focus

    ' set the focus back to the calculator window & calulate
    If Wsh.AppActivate (Calc_Title) Then
     Wsh.SendKeys "10"       ' send 10
     Wsh.SendKeys "{+}"      ' send +
     Wsh.SendKeys "2"        ' send 2
     Wsh.SendKeys "="        ' send =

     Wsh.SendKeys "^{c}"     ' send Ctrl+C, copy to clipboard
    End if

    ' set the focus to the editor window
    MsgBox "Paste result into editor window?", vbOkOnly + vbSystemModal
    If Wsh.AppActivate (Edit_Title) Then
     Wsh.SendKeys "Result of 10 {+} 2 ="
     Wsh.SendKeys "^{v}"     ' send Ctrl+v, paste from clipboard
    End if
    '* End

    You can use similar techniques also with other application programs. Then you need to send keystrokes to select portions of the document area (which can be a problem).


    Author Comment

    Const Edit_Title = "Path Group Maintenance"          ' window title
    DIM Wsh
    Set Wsh = WScript.CreateObject("WScript.Shell")
    Wsh.AppActivate (Edit_Title)

    That works awsome, hopefully when I switch back and forth 52000 times for what I need it to do it will still be working lol.


    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now