OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Print Sheet if cell value is "x"

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Weust
Newbie
Newbie


Joined: 22 Oct 2008
Posts: 1

PostPosted: Wed Oct 22, 2008 5:29 am    Post subject: Print Sheet if cell value is "x" Reply with quote

Can anyone help me please?

I'm trying to create a document in OOoCalc.

I want to make a button ond the first sheet wich can print different sheets if the value in different cells (P7,P8,P9, enz. till P31) is "x".

If the value in cell P7 = "x" then print sheet 2
If the value in cell P8 = "x" then print sheet 3
If the value in cell P9 = "x" then print sheet 4
enz. till
If the value in cell P31 = "x" then print sheet 26

This is how far i can get with it, but it wont work and keeps crashing.


Code:

Dim Doc As Object
Dim Sheet As Object
Dim CellRange As Object
Dim Cell As Object
dim i as integer

Doc = StarDesktop.CurrentComponent
Sheet = Doc.Sheets.getByName("Sheet1")
CellRange = Sheet.getCellRangeByName("P7:P31")

for i = 7 to 31
   if Sheet.getCellByPosition(16,i).String = "X" then
   subPrint(i)
   end if
next
End Sub

Sub subPrint(i as Integer)
Select Case i
   case 7: PrintSheet2 'i have a sub called PRINTSHEET2
   case 8: PrintSheet3 'i have a sub called PRINTSHEET3
End Select
End sub   


is there someone how can help me?


ps. Sorry for my bad English

Greets
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Wed Oct 22, 2008 7:28 am    Post subject: Reply with quote

Copy code from Re: How to print only one sheet
Code:

For r = 6 to 30
  oCell=oSheet.getCellByPosition(15,r)
  s= oCell.getString()
  if strComp(s, "x", 0) = 0 then exit for
next
if r > 30 then exit sub
oPS = thisComponent.SHeets.getByIndex(r -5)
oView = thisComponent.getCurrentCOntroller()
oView.setActiveSheet(oPS)

REM release range selection:
dummy = thiscomponent.createInstance("com.sun.star.sheet.SheetCellRanges")
oView.select(dummy)

PrintActiveSheet()

_________________
Rest in peace, oooforum.org
Get help on https://forum.openoffice.org
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group