VBS訪問(wèn)剪貼板的幾種方法小結(jié)
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate("about:blank")
Set clipboard = IE.document.parentWindow.clipboardData
'SetData設(shè)置剪切板的內(nèi)容
clipboard.SetData "text", "忘記了,喜歡一個(gè)人的感覺(jué)"
'GetData獲取剪切板的內(nèi)容
WScript.Echo clipboard.GetData("text")
IE.Quit
實(shí)踐證明,網(wǎng)上一搜一大把的代碼一般不是好代碼。SetData方法其實(shí)是和IE瀏覽器的設(shè)置有關(guān)的。
IE8的默認(rèn)設(shè)置是Prompt,所以運(yùn)行上面那個(gè)腳本的時(shí)候會(huì)彈出一個(gè)對(duì)話框,如果這是成Disable,那么這個(gè)腳本就無(wú)法設(shè)置剪貼板內(nèi)容了(獲取不受影響)。
這種沒(méi)有保證的代碼還是少用一些的好,在Windows 7下可以用clip.exe來(lái)設(shè)置剪貼板的內(nèi)容,獲取的話還是用IE就行了。
Dim WshShell set WshShell = CreateObject("wscript.Shell") str = "忘記了,喜歡一個(gè)人的感覺(jué)" WshShell.Run "cmd.exe /c echo " & str & " | clip",0,False
用Word.Application也可以設(shè)置和獲取剪貼板內(nèi)容
'設(shè)置剪切板的內(nèi)容 Dim Word Set Word = CreateObject("Word.Application") Word.Documents.Add Word.Selection.Text = "忘記了,喜歡一個(gè)人的感覺(jué)" Word.Selection.Copy Word.Quit False
'獲取剪切板的內(nèi)容 Dim Word Set Word = CreateObject("Word.Application") Word.Documents.Add Word.Selection.PasteAndFormat(wdFormatPlainText) Word.Selection.WholeStory str = Word.Selection.Text Word.Quit False WScript.Echo str
最神奇的是用Microsoft Forms 2.0 Object Library。
'設(shè)置剪切板的內(nèi)容 Dim Form, TextBox Set Form = CreateObject("Forms.Form.1") Set TextBox = Form.Controls.Add("Forms.TextBox.1").Object TextBox.MultiLine = True TextBox.Text = "忘記了,喜歡一個(gè)人的感覺(jué)" TextBox.SelStart = 0 TextBox.SelLength = TextBox.TextLength TextBox.Copy
'獲取剪切板的內(nèi)容 Dim Form, TextBox Set Form = CreateObject("Forms.Form.1") Set TextBox = Form.Controls.Add("Forms.TextBox.1").Object TextBox.MultiLine = True If TextBox.CanPaste Then TextBox.Paste WScript.Echo TextBox.Text End If
參考鏈接:
原文:http://demon.tw/programming/vbs-clipboard.html
- JS復(fù)制到剪貼板示例代碼
- JS/FLASH實(shí)現(xiàn)復(fù)制代碼到剪貼板(兼容所有瀏覽器)
- ASP.NET jQuery 實(shí)例4(復(fù)制TextBox的文本到本地剪貼板上)
- VBScript 剪貼板抓取URL并在瀏覽器中打開(kāi)
- [js]javascript與剪貼板交互
- 用vbscript實(shí)現(xiàn)將腳本的輸出復(fù)制到剪貼板
- 用vbs 實(shí)現(xiàn)從剪貼板中抓取一個(gè) URL 然后在瀏覽器中打開(kāi)該 Web 站點(diǎn)
- 一段多瀏覽器的"復(fù)制到剪貼板"javascript代碼
- vb.net借助剪貼板將圖片導(dǎo)入excel內(nèi)
相關(guān)文章
MSScriptControl.ScriptControl組件的用法實(shí)例
這篇文章主要介紹了MSScriptControl.ScriptControl組件的用法實(shí)例,需要的朋友可以參考下2014-08-08右鍵發(fā)送(sendto),創(chuàng)建快捷方式到自定義的位置
右鍵發(fā)送(sendto),創(chuàng)建快捷方式到自定義的位置...2007-03-03用vbs實(shí)現(xiàn)在啟動(dòng) Windows 資源管理器時(shí)打開(kāi)特定文件夾
首先創(chuàng)建 Wscript.Shell 對(duì)象的實(shí)例;它是 Windows Script Host 對(duì)象,我們用它來(lái)在另一腳本內(nèi)運(yùn)行腳本或可執(zhí)行文件2007-03-03