How convert a group of AutoShapes to Picture format (PNG) ?<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
<o></o>
Code below to copy and paste as PNG but I face two problems <o></o>
1- It pastes in active sheet not on sheet 2.
2- it names picture with random name.<o></o>
Then I used below code after some change, but new picture has White back ground color while my picture created with AutoShapes have no backgroung.
http://picasaweb.google.com/dossfm0q/UntitledAlbum02#5330891622590312098
My reference http://www.mrexcel.com/forum/showthread.php?t=233108&highlight=save+gif
<o>by Jaafar Tribak ******** type=text/javascript> vbmenu_register("postmenu_1140013", true); *********> Nov 10th, 2006, 06:27 AM
http://www.mrexcel.com/forum/member.php?u=13375
</o>
<o></o>
Code below to copy and paste as PNG but I face two problems <o></o>
1- It pastes in active sheet not on sheet 2.
2- it names picture with random name.<o></o>
HTML:
Sub PasteAsPNG()
Sheets("Sheet2").Shapes("Group 1").Copy
Sheets("Sheet2").PasteSpecial Format:="Picture (PNG)"
End Sub
Then I used below code after some change, but new picture has White back ground color while my picture created with AutoShapes have no backgroung.
http://picasaweb.google.com/dossfm0q/UntitledAlbum02#5330891622590312098
HTML:
Option Explicit
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
'\\ Declare a UDT to store a GUID for the IPicture OLE Interface
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
'\\ Declare a UDT to store the PNG information
Private Type uPicDesc
Size As Long
Type As Long
hPic As Long
hPal As Long
End Type
Private Const PNG = 2
Private Const PICTYPE_PNG = 1
Sub Picture_1()
SaveRangePic Sheet2.Shapes("Group 1"), ThisWorkbook.Path & "\Picture 1.PNG"
Sheet2.Pictures.Insert(ThisWorkbook.Path & "\Picture 1.PNG").Name = "PP"
Kill ThisWorkbook.Path & "\Picture 1.PNG"
End Sub
Sub SaveRangePic(SourceRange As Object, FilePathName As String)
Dim IID_IDispatch As GUID
Dim uPicinfo As uPicDesc
Dim IPic As IPicture
Dim hPtr As Long
'\\ Copy Range to ClipBoard
SourceRange.CopyPicture Appearance:=xlScreen, Format:=PNG
OpenClipboard 0
hPtr = GetClipboardData(PNG)
CloseClipboard
'\\ Create the interface GUID for the picture
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
'\\ Fill uPicInfo with necessary parts.
With uPicinfo
.Size = Len(uPicinfo) '\\ Length of structure.
.Type = PICTYPE_PNG '\\ Type of Picture
.hPic = hPtr '\\ Handle to image.
.hPal = 0 '\\ Handle to palette (if PNG).
End With
'\\ Create the Range Picture Object
OleCreatePictureIndirect uPicinfo, IID_IDispatch, True, IPic
'\\ Save Picture Object
stdole.SavePicture IPic, FilePathName
End Sub
My reference http://www.mrexcel.com/forum/showthread.php?t=233108&highlight=save+gif
<o>by Jaafar Tribak ******** type=text/javascript> vbmenu_register("postmenu_1140013", true); *********> Nov 10th, 2006, 06:27 AM
http://www.mrexcel.com/forum/member.php?u=13375
</o>