Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact
A1VBCode Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      

Home » Classic Visual Basic (VB 6 or earlier) » General Visual Basic » Clipboard.clear


Clipboard.clearExpand / Collapse
Author
Message
Posted 9/16/2008 10:53:32 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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
Post #25709
Posted 9/17/2008 7:22:27 AM


Forum God

Forum God

Group: Moderators
Last Login: 8/19/2014 9:06:52 AM
Posts: 1,908, Visits: 5,506
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

I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
Post #25713
Posted 10/11/2008 12:15:54 PM
Forum God

Forum God

Group: Moderators
Last Login: Today @ 8:16:53 AM
Posts: 1,107, Visits: 10,632
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
Post #25979
Posted 10/11/2008 12:26:24 PM


Forum God

Forum God

Group: Moderators
Last Login: 8/19/2014 9:06:52 AM
Posts: 1,908, Visits: 5,506
Mark (10/11/2008)
VBScript doesn't have direct access to the clipboard.

You learn something every day Mark.

Keith

I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
Post #25980
Posted 1/24/2010 7:28:32 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 1/24/2010 7:24:48 PM
Posts: 1, Visits: 2
Change clipboard to clip and you'll be fine.
Post #28733
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 1 (1 guest, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Admin, Mod, Mark, Keithuk

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 10:32pm