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
TgtChart.Activate
ActiveChart.Paste
'ActiveChart.Delete
'ActiveChart.ChartArea.Select
'ActiveChart.PlotArea.Select
'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"
TgtChart.Delete
MsgBox "Target Range Saved as JPG Image", vbOKOnly, "Job Over"
End Sub
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
TgtChart.Activate
ActiveChart.Paste
'ActiveChart.Delete
'ActiveChart.ChartArea.Select
'ActiveChart.PlotArea.Select
'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"
TgtChart.Delete
MsgBox "Target Range Saved as JPG Image", vbOKOnly, "Job Over"
End Sub
Thanks, Tamatam
No comments:
Post a Comment
Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.