Danad Guest
|
Posted: Sat Feb 21, 2004 6:12 pm Post subject: How To Select a Range While Macro Runs |
|
|
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. |
|