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

How To Select a Range While Macro Runs

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
Danad
Guest





PostPosted: Sat Feb 21, 2004 6:12 pm    Post subject: How To Select a Range While Macro Runs Reply with quote

Hi.

This is a sample from my manual (based on Sun's documentation). It has a lot of code about Writer, Calc and Database. The text (explanations about OOo API) is for Portuguese and Spanish readers, but the code is there, and programmers understands code in any language (I think).

Code:

'
' sample of XRangeSelectionListener use
'
Public aListener As Object
Public aResult As String
Public bSelecao As Boolean

Sub Main
'
   Dim oDoc As Object
   Dim oDocView As Object
   Dim oPlan As Object
   Dim aProp(2) As New com.sun.star.beans.PropertyValue
   '
   oDoc = ThisComponent
   oDocView = oDoc.getCurrentController()
   ' set a listener
   Set aListener = CreateUnoListener("oList_","com.sun.star.sheet.XRangeSelectionListener")
   ' add the listener
   oDocView.addRangeSelectionListener ( aListener )
   ' set the selection properties
   aProp(0).Name = "InitialValue"
   aProp(0).Value = "" '"$Planilha1.$A$1:$B$2"
   aProp(1).Name = "Title"
   aProp(1).Value = "Select an "
   aProp(2).Name = "CloseOnMouseRelease"
   aProp(2).Value = True
   ' begin selection
   bSelecao = False
   oDocView.startRangeSelection ( aProp () )
   Do While ( bSelecao = False)
      ' wait selection
   Loop
   ' remove the listener
   oDocView.removeRangeSelectionListener(aListener)
   ' do sth. with result
   If ( bSelecao = True And Len (aResult) > 0 ) Then
      MsgBox aResult
      oPlan = oDocView.getActiveSheet()
      oRange = oPlan.getCellRangeByName(aResult)
      oRange.CharHeight = 20
   Else
      MsgBox "Selection aborted"
   End If
'
End Sub

Sub oList_done ( oEvent )
   ' get the range name
   aResult = oEvent.RangeDescriptor
   bSelecao = True
End Sub

Sub oList_aborted ( oEvent )
   bSelecao = True
End Sub

Sub oList_disposing ()
   ' nothing to do
End Sub


If somebody is interested, visit www.openoffice.org.br/docajuda and look for "Introdução ao OpenOffice.org - Basic v2", or get it here:
http://www.openoffice.org.br/downloads/Introducao_OOo_Basic_v2.zip

The Spanish translation, at the time only v1, is here:
http://es.openoffice.org/files/documents/73/1249/IntroOOoBasic-es.zip

Sorry my english.

Good luck.

Danad.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets 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