How convert specific range from Excel to Image using VBA code

Hi All,

how to convert specific range of excel to image using VBA code

Ex:below excel sheet=sheet1 range from A2:B8 (Sheetname and range change dynamically) and save image in local folder like E:\testFolder

Name Marks
2 233
3 234
4 235
5 236
6 237
7 238
8 239

Output

@Manaswini_UI,

Refer this solution.

If you are ok to use marketplace package, use this one.

Hi @Manaswini_UI

Try the below Invoke VBA code:

Sub ExportRangeAsImage(sheetName As String, rangeAddress As String)
    Dim ws As Worksheet
    Dim rng As Range
    Dim chartObj As ChartObject
    Dim imgPath As String
    
    ' Dynamic sheet name and range
    sheetName = sheetName        ' Replace or make dynamic
    rangeAddress = rangeAddress  ' Replace or make dynamic
    
    Set ws = ThisWorkbook.Sheets(sheetName)
    Set rng = ws.Range(rangeAddress)
    
    ' Copy range as picture
    rng.CopyPicture Appearance:=xlScreen, Format:=xlPicture
    
    ' Add temporary chart
    Set chartObj = ws.ChartObjects.Add(Left:=rng.Left, Top:=rng.Top, Width:=rng.Width, Height:=rng.Height)
    
    ' Paste copied picture into chart
    chartObj.Activate
    chartObj.Chart.Paste
    
    ' Export chart as PNG
    imgPath = "E:\testFolder\RangeImage.png"  ' Ensure folder exists
    chartObj.Chart.Export Filename:=imgPath, FilterName:="PNG"
    
    ' Delete temporary chart
    chartObj.Delete
End Sub

XAML:
Sequence13.xaml (11.2 KB)

Text File:
Export image to folder.txt (1.1 KB)
Note: Change the path as per yours.

Output:

Hope it helps!!

Sure! Here’s a VBA script that dynamically converts a specified Excel range to an image and saves it to a local folder (like E:\testFolder). You can adjust the sheet name and range in variables.

Sub ExportRangeAsImage()
    Dim ws As Worksheet
    Dim rng As Range
    Dim filePath As String
    Dim chartObj As ChartObject
    Dim chartShape As Chart

    ' === Set dynamically (you can change these values or prompt via InputBox) ===
    Dim sheetName As String
    Dim startCell As String
    Dim endCell As String
    sheetName = "Sheet1"
    startCell = "A2"
    endCell = "B8"
    filePath = "E:\testFolder\RangeImage.png" ' Change as needed

    ' === Reference the worksheet and range ===
    Set ws = ThisWorkbook.Sheets(sheetName)
    Set rng = ws.Range(startCell & ":" & endCell)

    ' === Copy range as picture ===
    rng.CopyPicture Appearance:=xlScreen, Format:=xlPicture

    ' === Add temporary chart to paste the picture ===
    Set chartObj = ws.ChartObjects.Add(Left:=rng.Left, Top:=rng.Top, Width:=rng.Width, Height:=rng.Height)
    Set chartShape = chartObj.Chart
    chartShape.Paste

    ' === Export the chart as image ===
    chartShape.Export fileName:=filePath, FilterName:="PNG"

    ' === Clean up ===
    chartObj.Delete
    MsgBox "Image saved to: " & filePath, vbInformation
End Sub

Let me know if you want a version where it loops through multiple ranges or auto-names files!