• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

[VBA] export selected range as PNG with enhance resolution

smallxyz

New Member
I found the following code in exporting selected range into PNG.
It works well. However, the displayed image is a bit non-smooth, especially the font.
Is there a way to enhance the export resolution?

Thanks.

>>> use code - tags <<<

Code:
Sub CommandButton56_Click()
    Application.ScreenUpdating = False
    '---------------------
    Dim vFilePath As Variant
    Dim rSelection As Range
    Dim sDefaultName As String
    '---------------------
    If TypeName(Selection) <> "Range" Then
        MsgBox "Selection is not a range."
        Exit Sub
    Else
        Set rSelection = Selection
        vFilePath = Application.GetSaveAsFilename(InitialFileName:="Clip", FileFilter:="PNG (*.png), *.png")
       
        '--exit if cancelled by user
        If (vFilePath = False) Then
            Exit Sub
        Else
           
            '-- copy selected range as picture (not as bitmap)
            rSelection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
           
            '--Create an empty chart, slightly larger than exact size of range copied
            With ActiveSheet.ChartObjects.Add(Left:=rSelection.Left, Top:=rSelection.Top, Width:=rSelection.Width + 2, Height:=rSelection.Height + 2)
                With .Chart
                    ' clean up chart
                    .ChartArea.Format.Line.Visible = msoFalse
                   
                    ' paste and position picture
                    .Paste
                    With .Pictures(1)
                        .Left = .Left + 2
                        .Top = .Top + 2
                    End With
                   
                    ' export
                   
                    .Export CStr(vFilePath)
                End With
                ' remove no-longer-needed chart
                .Delete
            End With
        End If
    End If    
    '--------------------------
End Sub
 

vletm

Excel Ninja
smallxyz
Have You tried to set bigger cells sizes while export?
... if now, column width is eg 13 then change it to 39 as well as row height to x3
or
scale zoom while export?
 

smallxyz

New Member
Ya. Thanks vletm.
It helps a bit. But the font still remain not so smooth enough, even I use x3 or x4 zoom.
What is more, the output png file is also quite big.
 

vletm

Excel Ninja
smallxyz
That, how much can (= wise to) zoom depends of ranges resolution.
... and of course, large picture could increase its file size.
 
Top