将图片从用户表单复制到电子表格 [英] Copy picture from userform to spreadsheet

查看:65
本文介绍了将图片从用户表单复制到电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一张图片加载到用户窗体中包含的图像控件中.我想从用户窗体图像控件中复制图片并将其粘贴到电子表格中.我找到了一种在电子表格中创建OLEObject并以这种方式移动图像的方法

I have a picture loaded into an image control contained within a userform. I would like to copy the picture from the userform image control and paste it into a spreadsheet. I've found a means to create an OLEObject within the spreadsheet and move the image that way here , but I'm creating multiple spreadsheets and I don't want all the extra objects.

如果我进入VBA编辑器,进入用户窗体,进入图像控件,并使用鼠标在Picture属性中选择(位图)并将其复制,则可以将图片仅粘贴到电子表格中.

If I go into the VBA Editor, into the userform, into the image control, and using my mouse, select the (Bitmap) in the Picture property and copy it, I can paste just the picture into a spreadsheet.

如果我使用宏记录器执行相同的操作,则代码自然仅包括select和paste方法.如果我在代码中引用相同的picture属性,那么我得到的只是句柄.

If I use the macro recorder to do the same, the code naturally only includes the select and paste methods. And if I reference the same picture property within code, all I get back is the handle.

我已经进行了广泛的搜索,并且穷举了一下,而且找不到以编程方式抓住手柄并将图片粘贴到VBA中的任何方法.我对VBA还是很陌生,而且API级别的工作远远超出了我目前的能力.

I have searched extensively, and I believe exhaustively, and I can't find any means of programmatically grabbing the handle and pasting the picture in VBA. I'm fairly new to VBA as it is and API level work is well beyond my current abilities.

推荐答案

您可以导出到临时文件并从那里加载:

You can export to a temporary file and load from there:

Private Sub UserForm_Activate()

    TransferToSheet Me.Image1, Sheet1

End Sub

Private Sub TransferToSheet(picControl, sht As Worksheet)
    Const TemporaryFolder = 2
    Dim fso, p
    Set fso = CreateObject("scripting.filesystemobject")
    p = fso.GetSpecialFolder(TemporaryFolder).Path & "\" & fso.gettempname
    SavePicture picControl.Picture, p
    sht.Pictures.Insert p
    fso.deletefile p
End Sub

这篇关于将图片从用户表单复制到电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆