It is perfectly worked solution. If you need change the name of exported PNG, then change the condition if…then (if sFile=“FAIL” …)
Sub Cells2PNG2 'export cells to PNG
dim oDoc as object, oSheet as object, sDir$, sUrl, sFile$, oCell as object, oRange as object
const cRange="A1:BA54" 'your range to export
sDir=ConvertToUrl("d:\mypng") 'OUTPUT DIRECTORY
oDoc=ThisComponent
oSheet=oDoc.CurrentController.ActiveSheet 'current sheet
oCell=oSheet.getCellRangeByName("I25") 'cell I25
sFile=oCell.string 'string from I25
if sFile="FAIL" then
sFile=oSheet.getCellRangeByName("AB9").string & " " & sFile 'file name: AB9 I25
elseif sFile="" then 'empty cell I25
sFile=oSheet.getCellRangeByName("AB9").string 'AB9
if sFile="" then 'empty I29 and empty AB9
msgbox("No value in I25 or AB9." & chr(13) & "PNG isn't exported.", 48)
end if
end if
sUrl=sDir & "/" & sFile & ".png" 'url of exported PNG
rem copy&paste&export2PNG
oRange=oSheet.getCellRangeByName(cRange) 'your range
oDoc.CurrentController.Select(oRange)
Dim Args(2) As New com.sun.star.beans.PropertyValue
Args(0).Name="FilterName"
Args(0).Value="calc_png_Export"
Args(1).Name="FilterData"
rem .Value from macro recorder
Args(1).Value =Array(Array("Compression",0,9,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Interlaced",0,1,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Translucent",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PixelWidth",0,1192,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PixelHeight",0,1673,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("LogicalWidth",0,27522,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("LogicalHeight",0,38628,com.sun.star.beans.PropertyState.DIRECT_VALUE))
Args(2).Name="SelectionOnly"
Args(2).Value=True
oDoc.storeToUrl(ConvertToURL(sUrl), Args) 'save PNG
createUnoService("com.sun.star.frame.DispatchHelper").executeDispatch(oDoc.CurrentController.Frame, ".uno:Deselect", "", 0, array())
End Sub