Friday, 27 May 2016

VBA Macro to Save the Excel Range as Image

VBA Macro to Export Excel Range as Image to Clipboard
Sub Save_ExcelRange_As_Image()

Application.DisplayAlerts = False

Dim MyRange As Range
Dim NewChart As Chart

    Set MyRange = ThisWorkbook.Names("MyRng").RefersToRange

    ThisWorkbook.Sheets.Add(After:=Sheets(Sheets.Count()),Type:=xlChart).Name = "MyChart"
        Set TgtChart = ThisWorkbook.Charts("MyChart")
        'ThisWorkbook.Sheets.Add(After:=Sheets("Data"),Type:=xlChart).Name = "MyChart"         
        'ActiveChart.SetSourceData Source:=Range("MyRng")

        MyRange.CopyPicture xlScreen, xlPicture


 'Formatting Copied Named Range on the Chart       
    Selection.ShapeRange.ScaleHeight 1.1, msoFalse, msoScaleFromBottomRight
    Selection.ShapeRange.IncrementLeft 30
    Selection.ShapeRange.IncrementTop 125

'Exporting/Saving the Chart as a .jpg Image 
TgtChart.Export FileName:="C:\Users\Tamatam\Desktop\Temp\MyRange.jpg", Filtername:="JPG"

MsgBox "Target Range Saved as JPG Image", vbOKOnly, "Job Over"

End Sub

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your open Feedback only related to this Blog Posts. Please note that I cannot respond to the Anonymous Comments.

Subscribe to Blog Posts by Email

ExcelKingdom-Popular Posts