如何在vba中用api函数操作剪贴板Clipboard?

用api函数操作剪贴板Clipboard主要集中在读取剪贴板数据和将数据写入剪贴板两种。

用api函数将数据写入剪贴板主要的步骤为:

1.用GlobalAlloc函数分配内存空间

2.用GlobalLock函数锁定分配的内存空间

3.用CopyMemory函数将要写入的数据复制到分配的内存空间

4.用GlobalUnlock函数解锁内存空间

5.用OpenClipboard函数打开剪贴板

6.用EmptyClipboard函数清空剪贴板

7.用SetClipboardData函数设置剪贴板的数据格式和关联步骤1-4中分配的内存空间

8.用CloseClipboard函数关闭剪贴板

如以下是一个将字符串“我和你”复制到剪贴板中的代码:

用api函数将数据读取剪贴板数据的主要步骤为:

1.用OpenClipboard函数打开剪贴板

2.用GetClipboardData函数获取要读取的数据所在的内存对象的句柄

3.用GlobalLock函数锁定获得的内存对象,并返回内存对象的第一个内存字节的地址

4.用GlobalSize函数获得实际存储数据的字节数

5.用CopyMemory函数将剪贴板内存对象中的数据读取到变量中

6.用CloseClipboard函数关闭剪贴板

以下代码是读取上面的写入剪贴板的数据:

       

仅有1条评论 发表评论

  1. Artisanvrb /

    Century to a kind of destruction:

  2. Yamahaipn /

    XVII century was Nicholas Jarry [fr].

  3. Vortexrto /

    handwritten books were made,

  4. Maura /

    First of all I would like to say awesome blog! I had a quick question which I’d like to ask if you
    don’t mind. I was interested to find out how you center yourself
    and clear your thoughts before writing. I’ve had a tough time clearing my mind in getting my ideas
    out. I do enjoy writing however it just seems like the
    first 10 to 15 minutes are lost just trying
    to figure out how to begin. Any ideas or hints?
    Kudos!

  5. KitchenAidgkm /

    new texts were rewritten

  6. Weaponjuh /

    55 thousand Greek, 30 thousand Armenian

  7. Isaac /

    Thanks for finally talking about > 如何在vba中用api函数操作剪贴板Clipboard? – VBA – ExcelOffice【微信公众号:水星Excel】
    < Loved it!

  8. Ascentfwx /

    XVII century was Nicholas Jarry [fr].

  9. Weaponcxo /

    handwritten books were made,

  10. Holographicwjj /

    scroll. Go to Code Form

  11. Flashpaqgqq /

    XVII century was Nicholas Jarry [fr].

  12. Keypadanuf /

    XVII century was Nicholas Jarry [fr].

  13. Telecasternmo /

    XVII century was Nicholas Jarry [fr].

  14. Clamcasepxg /

    monuments related to deep

  15. Securitykph /

    number of surviving European

发表评论