相关疑难解决方法(0)

Excel 2013 64位VBA:剪贴板API不起作用

我曾经能够在Excel VBA中使用Windows API调用来设置剪贴板上的文本.但自从升级到64位Office 2013后,我不能.下面是一些没有错误的代码,但它也没有在剪贴板上设置任何文本.有人可以帮我测试和排除故障吗?

将下面的代码粘贴到VBA中的代码模块后,您可以通过键入在即时窗口中对其进行测试,Clipboard_SetData("Copy this to the clipboard.")并且应该在剪贴板上设置该文本,并且您可以将其粘贴到任何其他应用程序中.

(我使用的是Windows 8,因此我无法使用Microsoft Forms或数据对象来操作剪贴板.它在Windows 8上无法正常工作.)

更新和编辑:下面的代码已得到纠正,现在可以在64位Excel中正常工作,这要归功于Jason Kurtz的回答.如果您觉得这很有用,请投票给他答案.

Option Explicit

'Found 64-bit API declarations here: http://spreadsheet1.com/uploads/3/0/6/6/3066620/win32api_ptrsafe.txt
Private Declare PtrSafe Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As LongPtr) As LongPtr
Private Declare PtrSafe Function GlobalFree Lib "kernel32" (ByVal hMem As LongPtr) As LongPtr
Private Declare PtrSafe Function GlobalLock Lib "kernel32" (ByVal hMem As LongPtr) As LongPtr
Private Declare PtrSafe Function GlobalSize Lib "kernel32" (ByVal hMem As LongPtr) …
Run Code Online (Sandbox Code Playgroud)

64-bit winapi vba excel-vba office-2013

14
推荐指数
2
解决办法
2万
查看次数

标签 统计

64-bit ×1

excel-vba ×1

office-2013 ×1

vba ×1

winapi ×1