Greetings. I found a macro from a few years ago that works well for a project I’m working on. I was wondering if someone could help me modify it. The macro copies a range of cells, pastes it into Draw, and saves the copied cells as a png to the folder of my choosing. I’d like to skip the 2nd step (pasting it into Draw). I tried to just delete the “Paste bitmap into Draw” section, but that didn’t work. Below is the code from this post:
Sub SaveSheetAsBitmap
'Copy from Calc.'
oSpreadsheet = ThisComponent
oSpreadsheetController = ThisComponent.getCurrentController()
oSheet = oSpreadsheetController.getActiveSheet()
'oRange = oSheet.getCellRangeByname("A1:G100")'
'oSpreadsheetController.select(oRange)'
oSpreadsheetController.select(oSheet)
oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
oSpreadsheetFrame = oSpreadsheetController.getFrame()
oDispatcher.executeDispatch(oSpreadsheetFrame, ".uno:Copy", "", 0, Array())
'Paste bitmap into Draw.'
oDoc = StarDesktop.loadComponentFromUrl(_
"private:factory/sdraw", "_blank", 0, Array())
oDocController = oDoc.getCurrentController()
oDocFrame = oDocController().getFrame()
Dim props(0) As New com.sun.star.beans.PropertyValue
props(0).Name = "SelectedFormat"
props(0).Value = 2 'Apparently this means bitmap format'
oDispatcher.executeDispatch(oDocFrame, ".uno:ClipboardFormatItems", "", 0, props())
'Export to PNG file.'
Dim aExportProps(1) as new com.sun.star.beans.PropertyValue
aExportProps(0).Name = "URL"
aExportProps(0).Value = "file:///path/to/test.png"
aExportProps(1).Name = "MimeType"
aExportProps(1).Value = "image/png"
oExporter = createUnoService("com.sun.star.drawing.GraphicExportFilter")
oExporter.SetSourceDocument(oDocController.Selection)
oExporter.Filter(aExportProps)
End Sub
Thanks in advance!