Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Well, I went back to use the copyRange method, and somehow was able to get it to work this time - at least to resolve problem 1. Here is the code I have now:

Dim shtSource As Object
Dim rngPrintArea As Object
Dim shtReceipt As Object
Dim rngDest As Object
Dim oDestCell As New com.sun.star.table.CellAddress
Dim i As Integer

shtSource = oDoc.Sheets.getByName(sTransType)
rngPrintArea = shtSource.getCellRangeByName(sTransType & "PrintArea")
shtReceipt = oDoc.Sheets.getByName("Receipt")
shtReceipt.Unprotect("")

rngDest = shtReceipt.getCellRangeByName("ReceiptOne")
oDestCell.Sheet = rngDest.RangeAddress.Sheet
oDestCell.Column = rngDest.RangeAddress.StartColumn
oDestCell.Row = rngDest.RangeAddress.StartRow
shtSource.copyRange(oDestCell, rngPrintArea.RangeAddress)
rngDest.CellBackColor = RGB(255,255,255)
rngDest.ClearContents(128)  ' get rid of any buttons copied

rngDest = shtReceipt.getCellRangeByName("ReceiptTwo")
oDestCell.Sheet = rngDest.RangeAddress.Sheet
oDestCell.Column = rngDest.RangeAddress.StartColumn
oDestCell.Row = rngDest.RangeAddress.StartRow
shtSource.copyRange(oDestCell, rngPrintArea.RangeAddress)
rngDest.CellBackColor = RGB(255,255,255)
rngDest.ClearContents(128)  ' get rid of any buttons copied

' Make sure the columns are the right width
' Since receipts are stacked, changing one changes both
For i = 0 to rngPrintArea.Columns.getCount-1
    rngDest.Columns.getByIndex(i).Width = rngPrintArea.Columns.getByIndex(i).Width
Next i
shtReceipt.Protect("")

Dim view As Object
view = oDoc.getCurrentController()
view.setActiveSheet(shtReceipt) 
oDoc.Print(Array())
view.setActiveSheet(shtSource)

When I had tested copyRange before, I don't remember building up oDestCell like that, so maybe that was my problem. Anyway, this code seems to work for copying the range over to the receipt sheet. I still can't get the print to print the right sheet, but since that's a different problem, I think I will post it as a separate question, so it doesn't get lost.