Export range as image

后端 未结 2 456
执笔经年
执笔经年 2021-01-21 01:30

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

2条回答
  •  遇见更好的自我
    2021-01-21 01:55

    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
    

提交回复
热议问题