I saw the link xltoolbox.sourceforge.net/api/, but still don’t know how to use it.
Please give me a hand! Thanks.
1)How to use this API to export a chart as .PNG file?
2)Can I use the API to save Excel range as .PNG file?
It’s fairly simple. I attach a sample workbook with some VBA code in it that shows how to do it.
Here’s the pertinent code:
[code2=visual_basic]Sub TestAPI()
’ Tests the XL Toolbox API
’ To make this work, you need to add “Daniel’s XL Toolbox”
’ to the VBA project’s references (Visual Basic Editor, Menu “Extras”,
’ command “References”).
Dim objSheet As Worksheet
Dim lngRes As Long
' If the active sheet is a chart sheet, the
' following assignment will cause a run-time error
Set objSheet = ActiveSheet
' Select the chart
objSheet.ChartObjects(1).Select
' Export the selection to a file in the current folder
lngRes = XLTB_SaveSelectionAsFile("test_chart.png", _
dpi:=1200, _
colormode:=XLTB_ColorMode_Grayscale)
If lngRes <> 0 Then MsgBox "Exporting the chart did not work."
' Select a range
objSheet.Range("A1:A3").Select
' Export the selection
lngRes = XLTB_SaveSelectionAsFile("test_cells.png", _
dpi:=600, _
colormode:=XLTB_ColorMode_RGB)
If lngRes <> 0 Then MsgBox "Exporting the cells did not work."
End Sub[/code2]
Kind regards
Daniel