title: Copying text to clipboard using VBA
body: <p>In MS Excel 2010 I am trying to copy some text to the clipboard using <code>SendKeys</code>. However, it does not work.</p>
  
  <p>Is this some kind of security measure that Microsoft took in order to prevent people from creating fraudulent macros? Here's some code that shows what I'm trying to do (assume, that you're in the vba window and have some text selected):</p>
  
  <pre><code>Public Sub CopyToClipboardAndPrint()
      Call SendKeys("^(C)", True)
      Dim Clip As MSForms.DataObject
      Set Clip = New MSForms.DataObject
      Clip.GetFromClipboard
      Debug.Print Clip.GetText
  End Sub
  </code></pre>
  
  <p>Note that in order to use the MSForms.DataObject you'll have to reference <code>%windir%\system32\FM20.DLL</code> (i.e. Microsoft Forms 2.0 Object Library).</p>
  
  <p><hr/>
  <strong>Edit:</strong>
  The text I'm trying to copy is <em>not</em> in the document window, but in the immediate window of the vba project window! So Selection.Copy won't work here.</p>