作者:绿色风
分类:
时间:2022-08-17
浏览:112
楼主 xmyjk |
Q:如何直接将工作表中图表加载至IMAGE控件中(不另存图片文件)
A:思路,直接复制图片,然后访问剪贴板,将图片直接从剪贴板里头乾坤大挪移至IMAGE控件中。- Private Declare Function OpenClipboard Lib "User32" (ByVal hWnd As Long) As Long
- Private Declare Function CloseClipboard Lib "User32" () As Long
- Private Declare Function GetClipboardData Lib "User32" (ByVal uFormat As Long) As Long
- Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
- Private Type GUID
- Data1 As Long
- Data2 As Integer
- Data3 As Integer
- Data4(0 To 7) As Byte
- End Type
- Private Type PicBmp
- Size As Long
- Type As Long
- hBmp As Long
- hPal As Long
- Reserved As Long
- End Type
- Dim d
- Private Sub ListBox1_Click()
- Dim i%, Pic As PicBmp, IPic As IPicture, IID_IDispatch As GUID
- For i = 2 To 5
- If Cells(i, 1) = ListBox1.Text Then
- Label3.Caption = Cells(i, 1)
- Label4.Caption = Cells(i, 2)
- d(Label3.Caption & "|" & Label4.Caption).CopyPicture 1, 2
- OpenClipboard 0
- With IID_IDispatch
- .Data1 = &H20400
- .Data4(0) = &HC0
- .Data4(7) = &H46
- End With
- With Pic
- .Size = Len(Pic)
- .Type = 1
- .hBmp = GetClipboardData(2)
- End With
- CloseClipboard
- OleCreatePictureIndirect Pic, IID_IDispatch, 1, IPic
- Set Image1.Picture = IPic
- End If
- Next
- End Sub
- Private Sub UserForm_Initialize()
- Dim sh As Shape
- Set d = CreateObject("scripting.dictionary")
- For Each sh In Sheet1.Shapes
- If sh.Type = msoPicture Then
- Set d(sh.TopLeftCell.Offset(, -2) & "|" & sh.TopLeftCell.Offset(, -1)) = sh
- End If
- Next
- End Sub
image图片.rar |
2楼 亡者天下 |
谢谢分享 |
3楼 老糊涂 |
谢谢分享 |
免责声明
有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素,
经与ExcelTip.Net站长Apolloh商议并征得其同意,
现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示,
供有需要的人士查询使用,也慰缅曾经的论坛时代。
所示各个帖子的原作者如对版权有异议,
可与本人沟通提出,或于本站点留言,我们会尽快处理。
在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一