Excel 2013 64-bit VBA: Clipboard API doesn't work

后端 未结 3 595
北恋
北恋 2020-12-08 22:01

I used to be able to use Windows API calls in Excel VBA to set text on the clipboard. But ever since upgrading to 64-bit Office 2013, I cannot. Below is some code that doe

3条回答
  •  死守一世寂寞
    2020-12-08 22:39

    OK, I got it now...

    You need to change this line in your version of the code:

    Private Declare PtrSafe Function lstrcpy Lib "kernel32" (ByVal lpString1 As String, ByVal lpString2 As String) As LongPtr
    

    To this:

    Private Declare PtrSafe Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As LongPtr
    

    If you step through the code as you had it, you will see that the value of lpGlobalMemory changes when lstrcopy is called. When the types are changed to Any, the value stays the same.

    Works for me on windows 7. Hope it works for you!

提交回复
热议问题