
OSelection = oSelection.queryIntersection(oSheet.getRangeAddress()) If oSelection.supportsService(".SheetCellRanges") then REM Reduce a multiple sheet selection to active sheet:

REM so this routine can not print a single highlighted cell.ĭim oView, oSheet, oUsedRange, oSelection REM The API can not distinguish between a single cell being highlighted or not, REM print set up print ranges or the sheet's used range. REM If the selection is a single cell or not a range at all, REM Print active sheet's selection without prompting for details. IsVisible = (StrComp(sSheetName,s,0) = 0)Įnd Sub Edit: (StrComp(sSheetName,s,0)) = 0 PrintSingleSheetByMacro.ods (9.93 KiB) Downloaded 807 times OSheets.getByIndex(i).IsVisible = bSheetIsVisible(i) ' Restore the visibility status of all sheets ODoc = ĭispatcher = createUnoService(".DispatchHelper")ĭispatcher.executeDispatch(oDoc, ".uno:Print", "", 0, args2()) ' Print the document (only one visible sheet) If sSheetName oSheets.getByIndex(i).Name Then ' Hide all the sheets but the one we need to printīSheetIsVisible(i) = oSheets.getByIndex(i).IsVisible MsgBox "The sheet """ & sSheetName & """ does not exist in this document.

If sSheetName = oSheets.getByIndex(i).Name Then ' and restore their status immediately afterĭim args2(2) as New .PropertyValue

' The trick is to hide all sheets but the one to print ' This macro prints a single sheet based on its name Sub PrintSingleSheet(sSheetName as String) SSheetName = InputBox("Which sheet do you want to print?")
