Windows 7 - LO Version 5.2.3.3
Linux - LO Version 5.3.3
Have a multi sheet spreadsheet that prints only the currently open sheet with a “button activated macro”.
The two pages each have their own button and macro. The complete macros (Sheet1) and (Sheet2) are shown below.
These macros work on my Windows 7 computer. When “Sheet1” is open it only prints “Sheet1” on button click. When “Sheet2” is open it only prints “Sheet2” on button click.
The problem is when this spreadsheet is open on a Linux system it only prints Sheet1 for both “Sheet1” and “Sheet2”.
sub Sheet1
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Printer"
args1(0).Value = thiscomponent.Sheets.getByName("Settings").getcellbyposition(3,12).string
dispatcher.executeDispatch(document, ".uno:Printer", "", 0, args1())
rem ----------------------------------------------------------------------
dim args2(2) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Copies"
args2(0).Value = thiscomponent.Sheets.getByName("Settings").getCellRangeByName("D9").value
args2(1).Name = "RangeText"
args2(1).Value = "1"
args2(2).Name = "Collate"
args2(2).Value = true
dispatcher.executeDispatch(document, ".uno:Print", "", 0, args2())
rem ----------------------------------------------------------------------
document = ThisComponent 'assigns the current document to the variable document
Sheets = document.Sheets 'get the container of all Sheets
Sheet = Sheets.getByName("Sheet1") 'get the sheet named Sheet1
Controller = document.getcurrentController
Controller.setActiveSheet(Sheet)
end sub
sub Sheet2
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Printer"
args1(0).Value = thiscomponent.Sheets.getByName("Settings").getcellbyposition(3,12).string
dispatcher.executeDispatch(document, ".uno:Printer", "", 0, args1())
rem ----------------------------------------------------------------------
dim args2(2) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Copies"
args2(0).Value = thiscomponent.Sheets.getByName("Settings").getCellRangeByName("D5").value
args2(1).Name = "RangeText"
args2(1).Value = "1"
args2(2).Name = "Collate"
args2(2).Value = true
dispatcher.executeDispatch(document, ".uno:Print", "", 0, args2())
rem ----------------------------------------------------------------------
document = ThisComponent 'assigns the current document to the variable document
Sheets = document.Sheets 'get the container of all Sheets
Sheet = Sheets.getByName("Sheet2") 'get the sheet named Sheet2
Controller = document.getcurrentController
Controller.setActiveSheet(Sheet)
end sub