I get the below macro in my Excel document. I'm facing the error on exporting.
Error: Object doesnt support this property or method
Sub pic_gen()
Sheets("Email").Range("Print_Area").CopyPicture Appearance:=xlScreen, Format:=xlBitmap
Sheets("foremail").Select
ActiveSheet.Paste
Selection.Export ThisWorkbook.Path & "\sChartName.bmp"
End Sub
.Export
is a method which belongs to Chart
or ChartObject
class. You receive the error, because you try to use .Export
method on Selection
object which is of type Range
. You should first create a chart, then you will be able to export it.
This may work:
Sub RangeToPicture()
Dim chtObj As ChartObject
Dim rngPrint As Range
Set rngPrint = Sheets("Email").Range("Print_Area")
rngPrint.CopyPicture xlScreen, xlBitmap
Set chtObj = ActiveSheet.ChartObjects.Add(1, 1, rngPrint.Width, rngPrint.Height)
chtObj.Activate
ActiveChart.Paste
ActiveChart.Export ThisWorkbook.Path & "\sChartName.bmp"
chtObj.Delete
End Sub