Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

VBS to Copy Field Value to ClipboardHelpful Member! 

cwsstins (MIS) (OP)
6 Jan 06 15:04
I have users working in two applications. They have to copy a driver's license value from App1 and paste it into App2. However, App2 only accepts the number portion of the driver's license, not the (first two characters) state abbreviation. My users would like a way to just copy all but the first two characters without having to select it with the mouse because of user error in making the selection. Doesn't seem like a big deal, but it takes each user a couple seconds to copy. Multiply that by 50 users and 2,000+ records per day and it starts to impede productivity.

App1 has the capability to run external programs, such as .vbs files. I'd like to figure out a way using vbs to copy the applicable portion of the value (by dropping the first two characters) to the clipboard. From the research I've done, it looks like this can be done with the window.clipboardData.setData sub, but I'm not sure how to set the variable up to extract the data (without the first two characters) from the field.

Any help would be greatly appreciated.

stinsman
markdmac (MIS)
6 Jan 06 17:31
Yes you can do this but you will need to install WSHExtra.dll on the client PC.

http://www.windowsitpro.com/WindowsScripting/Article/ArticleID/23601/23601.html

Once you have WSHExtra you are able to copy to the clipboard.  You could easily have it strip the first two characters before sending to the clipboard using the Right Function.

Example:
Right(string,(Len(string)-2)).

I hope you find this post helpful.  

Regards,

Mark

cwsstins (MIS) (OP)
9 Jan 06 9:10
I registered the .dll and I'm trying to modify the "Listing_01.CopyClipboard.vbs" code to accommodate my needs, but I'm having trouble with it.

This is what I've got:

CODE

strArg = WScript.Arguments(0)
If strArg = "" Then
MsgBox "There is no driver's license to be copied", vbOkOnly+vbExclamation+vbSystemModal, "Driver's License"

Else

Dim clip
Set clip = CreateObject _
    ("WshExtra.Clipboard")

strText = clip.Paste()
    Set fso = CreateObject _
    ("Scripting.FileSystemObject")
    Set f = fso.CreateTextFile("note.txt")
    f.Write strText
    f.Close
End If

I'm know I'm way off here, but I don't know how to use this code. When I run this, nothing (apparently)happens.

How does the WshExtra.dll use the "note.txt" file? Do I just need to add that file to the C:\WINDOWS\System32 directory?

The field specified strArg is provided by an "Arguments" field in the application.
markdmac (MIS)
10 Jan 06 2:06
The example you have postged assumes that the user has already copied the value to the clipboard.

Since you are looking to strip the first two characters here is how you will want to do it.

CODE

Dim clip
Set clip = CreateObject _
    ("WshExtra.Clipboard")

Dim strText
strText = clip.Paste()

ShortTxt = Right(strText,(Len(strText)-2))

If strText <> "" Then
    msgbox ShortTxt
End If

I hope you find this post helpful.  

Regards,

Mark

markdmac (MIS)
10 Jan 06 2:17
And here is an example of how to take a variable or string and SEND it to the clipboard and then later paste it back out.  Note that it strips out the leading two digits as you requested.

CODE

Dim clip
Set clip = CreateObject _
    ("WshExtra.Clipboard")

Dim strText
Clip.Copy("001234hello")
strText = clip.Paste()

ShortTxt = Right(strText,(Len(strText)-2))

If strText <> "" Then
    msgbox ShortTxt
End If

I hope you find this post helpful.  

Regards,

Mark

cwsstins (MIS) (OP)
10 Jan 06 7:56
Mark, thanks for your help on this. That second one is what I need. But it doesn't seem to do what I'm looking for. I need for the script to copy the value to the clipboard and not paste it into a msgbox, but enable the user to manually paste it into another program when they're ready.

Seems like this should work, but it doesn't:

CODE

strArg = WScript.Arguments(0)

If strArg = "" Then
MsgBox "There is no driver's license to be copied", vbOkOnly+vbExclamation+vbSystemModal, "Driver's License"

Else

Dim clip
Set clip = CreateObject _
    ("WshExtra.Clipboard")

Clip.Copy(Right(strArg,(Len(strArg)-2)))

End If
Helpful Member!  mrmovie (TechnicalUser)
10 Jan 06 8:16
not my own work, not sure where it came from, works for me (i.e. i run the script then open notepad and do a cntrol-c and the text is there) but requires IE,

sText = "some text to clipboard"
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate "about:blank"
Do Until objIE.ReadyState=4: WScript.Sleep 1: Loop
objIE.Document.ParentWindow.ClipboardData.SetData "Text", sText
objIE.Quit
tsuji (TechnicalUser)
10 Jan 06 8:47
To get clipboard text data, take a look of this for instance.
    http://tek-tips.com/viewthread.cfm?qid=1115959&amp;page=1
cwsstins (MIS) (OP)
10 Jan 06 13:18
Thanks guys for your help and feedback!

I've got to test it out a bit, but I think the option mrmovie provided will work out best because the only requirement is that IE is installed, which is an absolute in my environment.

stinsman

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close