converting AutoShapes to Picture format PNG

Dossfm0q

Banned User
Joined
Mar 9, 2009
Messages
570
Office Version
  1. 2019
Platform
  1. Windows
How convert a group of AutoShapes to Picture format (PNG) ?<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Code below to copy and paste as PNG but I face two problems <o:p></o:p>
1- It pastes in active sheet not on sheet 2.
2- it names picture with random name.<o:p></o:p>


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:p>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:p>
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,223,288
Messages
6,171,213
Members
452,391
Latest member
BHG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top