How VBS accesses the clipboard
This article mainly introduces how VBS accesses the clipboard, which has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.
The code is as follows:
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate("about:blank")
Set clipboard = IE.document.parentWindow.clipboardData
'SetData Sets the contents of the clipboard
clipboard.SetData "text", "Forget, like a person's feeling"
'GetData Gets the contents of the clipboard
WScript.Echo clipboard.GetData("text")
IE.Quit
Practice has proved that a large number of online search code is generally not good code. The SetData method is actually related to IE browser settings.
The default setting for IE8 is Prompt, so running the script above will pop up a dialog box. If this is Disabled, then the script will not be able to set the clipboard contents (get unaffected).
This code is not guaranteed or less good, in Windows 7 can be used to set the contents of the clipboard clip.exe, get it or use IE on the line.
Dim WshShellset WshShell = CreateObject("wscript.Shell")str = "Forget, like a person's feeling"WshShell.Run "cmd. exe/c echo " & str & "| clip",0,False
Word.Application can also be used to set and get clipboard contents
'Set the contents of the clipboard Dim WordSet Word = CreateObject("Word.Application")Word.Documents.AddWord.Selection.Text = "Forget, like a person's feeling"Word.Selection.CopyWord.Quit False' Get the contents of the clipboard Dim WordSet Word = CreateObject("Word.Application")Word.Documents.AddWord.Selection.PasteAndFormat(wdFormatPlainText)Word.Selection.WholeStorystr = Word.Selection.TextWord.Quit FalseWScript.Echo str
Microsoft Forms 2.0 Object Library.
'Set the contents of the clipboard Dim Form, TextBoxSet Form = CreateObject ("Forms.Form.1")Set TextBox = Form.Controls.Add ("Forms.TextBox.1").ObjectTextBox.MultiLine = TrueTextBox.Text = "Forget, like a person's feelings"TextBox.SelStart = 0TextBox.SelLength = TextBox.TextLengthTextBox.Copy'Get the contents of the clipboard Dim Form, TextBoxSet Form = CreateObject ("Forms.Form.1")Set TextBox = Form.Controls.Add ("Forms.TextBox.1").ObjectTextBox.MultiLine = TrueIf TextBox.CanPaste Then TextBox.Paste WScript.Echo TextBox.TextEnd If Thank you for reading this article carefully, Hope Xiaobian shared "VBS how to access the clipboard" this article is helpful to everyone, but also hope that everyone a lot of support, pay attention to the industry information channel, more relevant knowledge waiting for you to learn!