Automation中经常需要程序和剪切板交互,还在使用键盘一个一个input?内容多的话,岂不是太慢了,使用剪切板的黏贴复制,so fast,so easy……具体需要调用Microsoft Forms 2.0 Object Library的对象和方法,用它轻松实现设置和获取剪切板的内容,下面写了2个设置和获取剪切板内容的函数,需要的时候直接调用~
'operating clipboard Function setClipboard(str) 'setting clipboard's content Dim Form, TextBox Set Form = CreateObject("Forms.Form.1") Set TextBox = Form.Controls.Add("Forms.TextBox.1").Object TextBox.MultiLine = True TextBox.Text = str TextBox.SelStart = 0 TextBox.SelLength = TextBox.TextLength TextBox.Copy End Function Function getClipboard 'getting clipboard's content 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 getClipboard = TextBox.Text End If End Function