Move list box items to a specific sheet

(See also : https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=85322; edited by @Lupp )

Good Afternoon.

I’m realizing a program in libreoffice calc…

At the moment, i want to move list box (“ListBox_Previa”) items to a specific area (“D60 - D71”) of a sheet (“EVOLUCAO”).

i need to a macro to do this work when i click in a button in a dialog…

someone can i help me ? please… urgent!!!

Edit: moved from answer posted by @ago_med

i’ll explain with pictures…

The first image show the dialog that contains, at the right, the “ListBox_Previa” named (“PREVIA DA PRESCRICAO MEDICA”).

In the Listbox exists 4 itens… This itens, i need to move, when i click at the button “Finalizar Prescriçao”, to a specific sheet named “EVOLUCAO” between D60 - D71, how show the seoond image below…

Thanks for everything…

Do you want to move the position of the listbox or copy the contents of the listbox to the cells?

Does the listbox already exist on the sheet “EVOLUCAO” and you just want to change the position and size to match the area D60:D71? If the listbox exists on a different sheet then you need to make a new listbox for the sheet “EVOLUCAO” and copy across the settings to the new listbox.

i need to copy the contents of the listbox to the cells…

the listbox don’t exist in a sheet… the listbox is in a dialog box…

I moved your explanation from your answer to your question. It might be easier for others to understand your question. I deleted my previous answer but now I have a better understanding of what you want I’ll answer again in a few hours.

If you could delete your own answer, now that I copied the info to your question it is no longer required and might cause some confusion later.

Thanks a lot … mark_t

It’s exactly what i needed…

@ago_med: If you post the same question to different forums please remember to include links between the posts as @Lupp has added in this question. This will help avoid someone spending time to answer a question that has already been answered in the other forum.

Ok… Thanks…

If you assign the following macro to the action event of the button on your dialog, then it should find the listbox of the given name from the same dialog, and then copy the text from the listbox to the specified cells on the named sheet.

Let me know if you have any problems, I didn’t include much in the way of error trapping.

Edit to simplify the method of finding the named listbox from the controls of the dialog, now that I realise that getControl method is applied to Context and not the array of Controls.

Sub CopyListBoxButton(oEvent As Object)
'	Assign this macro to the button action event'

	Dim oListBox As Object
	Dim oSheet As Object
	Dim oRange As Object
	Dim i As Integer
	
	oListBox = oEvent.Source.Context.getControl("ListBox_Previa")
	
	oSheet = ThisComponent.Sheets.getByName("EVOLUCAO")
	oRange = oSheet.getCellRangeByName("D60:D71").RangeAddress
	
	For i = 0 To oRange.EndRow - oRange.StartRow
		if i >= oListBox.ItemCount Then Exit For
		oSheet.getCellByPosition(oRange.StartColumn,oRange.StartRow + i).String = oListBox.Items(i)
	Next i
End Sub

Thanks a lot … mark_t

It’s exactly what i needed…

No problem, its a learning exercise for me too. If you could also please check the tick mark next to my answer so your question is shown as answered.