"My.Computer.Clipboard"对象在 Excel 中



>有谁知道如何在Excel中使用"My.Computer.Clipboard"对象。我已经通过转到工具->参考尝试了几乎所有的参考。我想使用这样的代码

If My.Computer.Clipboard.ContainsImage() Then
Dim grabpicture As System.Drawing.Image
grabpicture = My.Computer.Clipboard.GetImage()
picturebox1.Image = grabpicture
End If

https://learn.microsoft.com/en-us/dotnet/visual-basic/developing-apps/programming/computer-resources/storing-data-to-and-reading-from-the-clipboard

谢谢

在模块中,将此代码(或与测试代码放在同一模块中(:

Option Explicit
#If Win64 Then
Public Declare PtrSafe Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long
#Else
Public Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long
#End If

比 ,您可以通过以下代码进行测试。

If IsClipboardFormatAvailable(2) <> 0 Or IsClipboardFormatAvailable(14) <> 0 Then ...

注意:14 用于图元文件,2 表示位图。

注2:这适用于64位和32位Excel。

注3:用于查看文本是否存在:if IsClipboardFormatAvailable(1)<>0 then ...

要将数据(图像(从剪贴板获取到图像控件(我猜是在用户窗体中(,请使用Me.Image1.Picture = PastePicture,您也可以通过谷歌搜索"ModPastePicture"找到其代码,因为这不是适合 vba 的方法。这比将图片保存到磁盘+在控制图像中重新加载要快得多。

最新更新