|
原帖由 lxlaner 於 2008-11-22 23:25 發表
樓上的兄弟可否附一個文件上來,你的網址打不開
附件已上傳
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Type uPicDesc
Size As Long
Type As Long
hPic As Long
hPal As Long
End Type
Private Declare Function IsClipboardFormatAvailable Lib "user32" ( _
ByVal wFormat As Integer) As Long
Private Declare Function OpenClipboard Lib "user32" ( _
ByVal hwnd As Long) As Long
Private Declare Function GetClipboardData Lib "user32" ( _
ByVal wFormat As Integer) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" ( _
PicDesc As uPicDesc, RefIID As GUID, ByVal fPictureOwnsHandle As Long, _
IPic As IPicture) As Long
Private Declare Function CopyEnhMetaFile Lib "gdi32" Alias "CopyEnhMetaFileA" ( _
ByVal hemfSrc As Long, ByVal lpszFile As String) As Long
Private Declare Function CopyImage Lib "user32" (ByVal handle As Long, _
ByVal un1 As Long, ByVal n1 As Long, _
ByVal n2 As Long, ByVal un2 As Long) As Long
Private Sub UserForm_Activate()
Me.ComboBox1.ListIndex = 0
End Sub
Private Sub UserForm_Initialize()
Dim pic As Shape
For Each pic In ActiveSheet.Shapes
If pic.Type = msoPicture Then
Me.ComboBox1.AddItem pic.Name
End If
Next pic
End Sub
Private Sub ComboBox1_Change()
rTemp = ThisWorkbook.Path & "\" & Me.ComboBox1.Text & ".jpg"
'save a shape
SavePicture PictureFromObject(ActiveSheet.Shapes(Me.ComboBox1.Text)), rTemp
Me.Image1.Picture = LoadPicture(rTemp)
'等待10秒後刪除
Dim rtime As Date
rtime = DateAdd("s", 10, Now())
Kill rTemp
End Sub
Function PictureFromObject(Target As Object) As IPictureDisp
Dim hPtr As Long, PicType As Long, hCopy As Long
Const CF_BITMAP = 2
Const CF_PALETTE = 9
Const CF_ENHMETAFILE = 14
Const IMAGE_BITMAP = 0
Const LR_COPYRETURNORG = &H4
Const PICTYPE_BITMAP = 1
Const PICTYPE_ENHMETAFILE = 4
'將shape圖片複製到剪貼簿(以BITMAP 圖片的格式複製)
Target.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
'檢測剪貼板內資料的類型
PicType = IIf(IsClipboardFormatAvailable(CF_BITMAP) <> 0, _
CF_BITMAP, CF_ENHMETAFILE)
If IsClipboardFormatAvailable(PicType) <> 0 Then
If OpenClipboard(0) > 0 Then
hPtr = GetClipboardData(PicType)
If PicType = CF_BITMAP Then
'複製圖片並以BITMAP 圖片格式同時轉換為檔案
hCopy = CopyImage(hPtr, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG)
Else
'複製圖片並以ENHMETAFILE 圖片格式同時轉換為檔案
hCopy = CopyEnhMetaFile(hPtr, vbNullString)
End If
CloseClipboard
If hPtr <> 0 Then
Dim uPicInfo As uPicDesc, IID_IDispatch As GUID, _
IPic As IPictureDisp
With IID_IDispatch
.Data1 = &H7BF80980
.Data2 = &HBF32
.Data3 = &H101A
.Data4(0) = &H8B
.Data4(1) = &HBB
.Data4(2) = &H0
.Data4(3) = &HAA
.Data4(4) = &H0
.Data4(5) = &H30
.Data4(6) = &HC
.Data4(7) = &HAB
End With
With uPicInfo
.Size = Len(uPicInfo)
.Type = IIf(PicType = CF_BITMAP, _
PICTYPE_BITMAP, PICTYPE_ENHMETAFILE)
.hPic = hCopy
End With
OleCreatePictureIndirect uPicInfo, IID_IDispatch, True, IPic
Set PictureFromObject = IPic
End If
End If
End If
End Function
[ 本帖最后由 chijanzen 于 2008-11-22 23:52 编辑 ] |
评分
-
1
查看全部评分
-
|