| | | Forum Newbie
       
Group: Forum Members Last Login: 9/17/2008 1:22:44 AM Posts: 1, Visits: 6 |
| I am using Clipboard.clear in my VB script. But every time i run that script i get an error message "object required:Clipboard".
Can someone help me in creating a simple VB script that clears the content in the Windows Clipboard.
As of now this is my script:
Dim clip
Set clip = CreateObject _
("WshExtra.Clipboard")
Dim strText
strText = clip.Paste()
If strText <> "" Then
Set fso = CreateObject _
("Scripting.FileSystemObject")
Set f = fso.CreateTextFile("c:ote.txt")
Clipboard.Clear
f.Write strText
f.Close
End If
Thanks
sachin |
| | | | 
Forum God
       
Group: Forum Members Last Login: Yesterday @ 4:36:16 PM Posts: 1,463, Visits: 3,400 |
| Welcome to A1vbcode sachin.  nickoo (9/16/2008) I am using Clipboard.clear in my VB script. But every time i run that script i get an error message "object required:Clipboard". Can someone help me in creating a simple VB script that clears the content in the Windows Clipboard.
As of now this is my script:
Dim clip Set clip = CreateObject _ ("WshExtra.Clipboard")
Dim strText strText = clip.Paste()
If strText <> "" Then Set fso = CreateObject _ ("Scripting.FileSystemObject") Set f = fso.CreateTextFile("c:ote.txt")
Clipboard.Clear
It depends what you are calling VB script? Normal VB code or VBA? You don't have to Set anything to use Clipboard.Clear it does just that Clears anything in the Clipboard. Maybe the problem is with clip I've never used WshExtra.Clipboard just to copy text from a TextBox or what ever you are trying to do. I wouldn't have thought that Set f = fso.CreateTextFile("c:ote.txt") wouldn't have worked because you are missing "c:\ote.txt" a \ 
Keith http://www.martin2k.co.uk/forums/ I've been programming with VB for 12 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning. |
| | | | Forum God
       
Group: Forum Members Last Login: Today @ 4:38:01 AM Posts: 886, Visits: 5,287 |
| | VBScript doesn't have direct access to the clipboard. You would have to use a backdoor to access it. Two possible options are using the clipboard through Word or IE. I would first try the clipboard object in Word because won't get a security warning there. Option Explicit Dim objClip, strText
strText = InputBox("Enter text to copy to clipboard") Set objClip = CreateObject("Word.Application") If Not objClip Is Nothing Then With objClip .Visible = False .Documents.Add .Selection.TypeText strText .Selection.WholeStory .Selection.Copy .Quit False End With Else Set objClip = CreateObject("InternetExplorer.Application") objClip.Navigate ("about:blank") objClip.document.parentwindow.clipboardData.SetData "text", strText objClip.Quit End If Set objClip = Nothing
|
| | | | 
Forum God
       
Group: Forum Members Last Login: Yesterday @ 4:36:16 PM Posts: 1,463, Visits: 3,400 |
| Mark (10/11/2008) VBScript doesn't have direct access to the clipboard.You learn something every day Mark. 
Keith http://www.martin2k.co.uk/forums/ I've been programming with VB for 12 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning. |
| |
|
|