For a while now, my colleagues and me have been using all kinds of methods to create a template to easily make volunteer vacancy forms.
Ideally, the person in charge of
EDIT: added a line to remove the border from around the chartobject
Sub Tester()
Dim sht as worksheet
Set sht = ThisWorkbook.Worksheets("Sheet1")
ExportRange sht.Range("B2:H8"), _
ThisWorkbook.Path & "\" & sht.Range("J3").Value
End Sub
Sub ExportRange(rng As Range, sPath As String)
Dim cob, sc
rng.CopyPicture Appearance:=xlScreen, Format:=xlPicture
Set cob = rng.Parent.ChartObjects.Add(10, 10, 200, 200)
'remove any series which may have been auto-added...
Set sc = cob.Chart.SeriesCollection
Do While sc.Count > 0
sc(1).Delete
Loop
With cob
.ShapeRange.Line.Visible = msoFalse '<<< remove chart border
.Height = rng.Height
.Width = rng.Width
.Chart.Paste
.Chart.Export Filename:=sPath, Filtername:="PNG"
.Delete
End With
End Sub
I have been using this a few months, but after upgrading to windows 10 / excel 2016, the export is a blank image. And found that Excel 2016 is a bit slowminded and need everything bit by bit... the with... section should not contain the delete method and the chart need to be activated before paste...
like this:
mychart.Activate
With mychart
.Height = rng.Height
.Width = rng.Width
.Chart.Paste
.Chart.Export Filename:=strTempfile, Filtername:="PNG"
End With
mychart.Delete