What i want for a macro to do:
1) Take data from cells and put it into ListBox1 (done)
2.1) On pressing a button add an entry from ListBox1 to ListBox2 AND do not overwrite it if the next entry is added
2.2) if entry goes from ListBox1 to ListBox2, remove it from ListBox1
2.3) make multi selection to work
3) Use entries from ListBox1 for some anything, for example simply add to a cell or cells
2.1,2.2 and 2.3 are the ones i don't understad how to do. I can't find any info on the internet about ListBox unless its listbox inside the document and not macross type form that i need.
Is there're a simple option to add an entry to ListBox like .InsertData or is there more sophisticated way of doing this?
Code: Select all
Dim MyArr() As String
Dim MyArr2() As String
Dim MyString as String
Dim oDialog1 as Object
Dim oSheet
Function CountColumnsRows(Doc,SheetIndex,NumColumns,NumRows)
Sheet = Doc.Sheets.getByIndex(SheetIndex)
Curs = Sheet.createCursor
Curs.gotoEndOfUsedArea(True)
NumRows = Curs.Rows.Count
NumColumns = Curs.Columns.Count
End Function
Sub Dialog1Show()
DialogLibraries.LoadLibrary("Standard")
oDialog1 = CreateUnoDialog( DialogLibraries.Standard.Dialog1 )
oSheet = thisComponent.Sheets(0)
REM Count Rows for first Sheet of this document
CountColumnsRows(ThisComponent,0,NumColumns,NumRows)
Redim MyArr(NumRows) As String
Redim MyArr2(NumRows) As String
row=0
col=1
while row <> NumRows
MyArr(row)=oSheet.getCellByPosition(col,row).String
row=row+1
wend
oDialog1.getControl("ListBox1").getModel().StringItemList = MyArr()
oDialog1.Execute()
End Sub
Sub Dialog1Box()
MyArr2(0) = oDialog1.getControl("ListBox1").getSelectedItem()
oDialog1.getControl("ListBox2").getModel().StringItemList = MyArr2()
End Sub
Sub Dialog1Action()
oSheet.getCellByPosition(5,5).String = MyArr2(0)
End Sub