The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
Clipboard Usage
Posted: 25 May 07 11:08 AM
|
Is there a way in VBA to copy a string to the Windows Clipboard. I see functions to clear and read the Clipboard, but I don't see any method for writing to the Clipboard. |
|
|
|
Re: Clipboard Usage
Posted: 25 May 07 11:16 AM
|
Yeah, it's a real bummer that Sage didn't add in methods to copy to the clipboard when they added those to read from the clipboard. The problem is that there's no built-in ways in VBScript to access clipboard. However, a quick trick might work for you. If you are able to place a hidden textbox or memo control on a form, you can add your text to that and then use it's CopyToClipboard method.
ie:
' copy some text to the clipboard Edit1.Text = "Copy this text to the clipboard." & vbCrLf & "Goodbye and thanks for all the fish!" Edit1.CopyToClipboard ' my text is now on the clipboard
Make sense? |
|
|
|
Re: Clipboard Usage
Posted: 25 May 07 1:39 PM
|
fiogf49gjkf0d Ryan, Thanks for getting back to me quickly. I tried the 'CopyToClipboard' method and can report that it does not work. Maybe I'm doing something wrong, but nothing shows up in the clipboard. I even tried a few combinations of things without any luck. The instructions appear to run, but produce zero results. At least thanks for trying to help, Bob
|
|
|
|
Re: Clipboard Usage
Posted: 25 May 07 1:43 PM
|
fiogf49gjkf0d It's been a while since I used that, but I have used that before and it worked fine for me. One thing I can't remember, is if CopyToClipboard copies the selected text or all text. If it copies only the selected text then you'd add a call to SelectAll:
' copy some text to the clipboard Edit1.Text = "Copy this text to the clipboard." & vbCrLf & "Goodbye and thanks for all the fish!" Edit1.SelectAll Edit1.CopyToClipboard ' my text is now on the clipboard
Give that a try. |
|
|
|
Re: Clipboard Usage
Posted: 25 May 07 2:03 PM
|
fiogf49gjkf0d YES! That's the answer. I never thought to use that combination. But it works like a charm. I even added a 'Application.clipboard.clear' before the '.selectall' to make sure that only the intended text is copied. Much thanks, Regards, Bob
|
|
|
|
Re: Clipboard Usage
Posted: 12 Aug 09 4:17 AM
|
I might be being a bit dumb here, but how does this work if you are working from within an independent script that is not attached to a form? Is there any way of declaring a textbox as an object using script?
Thank you! |
|
|
|
Re: Clipboard Usage
Posted: 12 Aug 09 5:35 AM
|
Accessing the clipboard through VBS is actually a PITA and it does not appear to be possible directly.
Here is a way that may work for you, depending on your IE security settings:
set ie=createobject("internetExplorer.application") ie.navigate "about:blank" do until ie.readystate=4: wscript.sleep 1: loop ie.document.parentwindow.clipboardData.setData "Text", "test"
Adding about:blank to the list of Trusted sites in IE should make any error/warning prompts go away.
Phil |
|
|
|
Re: Clipboard Usage
Posted: 12 Aug 09 8:53 AM
|
That was just crazy enough to work.
I didn't realise you could grab hold of IE for that purpose. It gives a "application it trying to use the clipboard" confirmation dialog that I have to agree to first, but for the sake of testing code (such as copying failed SQL statements to the clipboard), it is ideal!
Thank you! |
|
|
|
Re: Clipboard Usage
Posted: 12 Aug 09 9:07 AM
|
Don't need to do that, you could use the Application.Clipboard functions. AsText is a Read/Write Property. See my sample code below (I have used it many times and just verified in 7.5 before replying):
'Clear the Clipboard: Application.Clipboard.Clear
'Set the Clipboard: Application.Clipboard.AsText = "This is the text I want on the Clipboard"
'Read the Clipboard: msgbox Application.Clipboard.AsText |
|
|
|
Re: Clipboard Usage
Posted: 12 Aug 09 9:09 AM
|
Originally posted by Robert Levine
Is there a way in VBA to copy a string to the Windows Clipboard. I see functions to clear and read the Clipboard, but I don't see any method for writing to the Clipboard. |
|
The AsText is not a function, but rather a Read/Write Property, you could use it to Read and Write to the Clipboard. |
|
|
|
Re: Clipboard Usage
Posted: 12 Aug 09 9:22 AM
|
Aha!
When I was reading the Saleslogix Developers Ref, it is worded as though it was Read Only so I didn't bother trying. However, you're right, I just tried it and it worked! That's twice in one day Raul. I'm posting another in a minute, see if you can make it a hat trick 
Application.Clipboard AsText Exposed In Version 6.2 Function Returns the current contents of the Windows clipboard. Object Application.Clipboard.AsText Syntax AsText( = Value) Parameters None Returns String - the current contents of the clipboard. Related Topics N/A |
|
|
|
Re: Clipboard Usage
Posted: 12 Aug 09 9:59 AM
|
We are using SLX 6.1000 around here for one customer so we still don't have the application.clipboard stuff....
As suggested, we use IE for the clipboard and it does quite nicely.
One caveat, the user's internet explorer security options for the internet must Enable or Prompt for Scripts: Allow Programmatic clipboard access. If it's disabled you'll get some bad results. |
|
|
|