VBA - Range to jpg picture

后端 未结 2 1858
暗喜
暗喜 2020-12-03 13:19

I\'m trying to get a jpg file from a specific range in excel

I\'m currently getting the

1004 Runtime error on Range method from _Worksheet ob

2条回答
  •  情歌与酒
    2020-12-03 14:02

    Here is how to export in the same path as the workbook :

    Sub Export()
    Dim ws As Worksheet
    Dim Rng As Range
    Dim Chrt As Chart
    Dim ExportPath As String
    
    Set ws = ActiveSheet
    Set Rng = ws.Range("B2:H11")
    ExportPath = ThisWorkbook.Path & "\Case.jpg"
    
    Set Chrt = ThisWorkbook.Charts.Add
    Rng.CopyPicture xlScreen, xlBitmap   
    
    With Chrt
        .Paste
        .Export FileName:=ExportPath, Filtername:="JPG"
    End With
    End Sub
    

提交回复
热议问题