Save range as picture

YasserKhalil

Well-known Member
Joined
Jun 24, 2010
Messages
852
Hello everyone
I have found this code that is supposed to save range as picture
Code:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Sub SaveLogoAsGif()
    Dim MyChart     As Chart
    Dim objPict     As Object
    Dim RgCopy      As Range


    On Error Resume Next
        Set RgCopy = Application.InputBox("Select The Range To Copy / Save As", "Selection Save", Selection.Address, Type:=8)
        If RgCopy Is Nothing Then Exit Sub
    On Error GoTo 0


    RgCopy.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
    ActiveSheet.PasteSpecial Format:="Bitmap"
    Set objPict = Selection


    With objPict
        .CopyPicture 1, 1
        Set MyChart = ActiveSheet.ChartObjects.Add(1, 1, .Width + 8, .Height + 8).Chart
    End With


    With MyChart
        .Paste
        .Export ThisWorkbook.Path & Application.PathSeparator & "Temp.gif"
        .Parent.Delete
    End With


    objPict.Delete
    Set RgCopy = Nothing
    Set objPict = Nothing


    ShellExecute 0, vbNullString, ThisWorkbook.Path & Application.PathSeparator & "Temp.gif", vbNullString, vbNullString, vbMaximizedFocus
End Sub

It exports the picture but it is blank .. Any ideas?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Forum statistics

Threads
1,214,893
Messages
6,122,118
Members
449,066
Latest member
Andyg666

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