Ask Your Question

Move list box items to a specific sheet

asked 2016-09-26 20:56:55 +0200

ago_med gravatar image

updated 2016-09-30 21:33:28 +0200

Lupp gravatar image

(See also :; 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").

image description

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...

image description

Thanks for everything...

edit retag flag offensive close merge delete


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

mark_t gravatar imagemark_t ( 2016-09-26 21:23:11 +0200 )edit

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.

mark_t gravatar imagemark_t ( 2016-09-27 00:00:07 +0200 )edit

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

ago_med gravatar imageago_med ( 2016-09-28 03:10:29 +0200 )edit

the listbox don't exist in a sheet... the listbox is in a dialog box...

ago_med gravatar imageago_med ( 2016-09-28 03:11:30 +0200 )edit

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.

mark_t gravatar imagemark_t ( 2016-09-28 03:27:58 +0200 )edit

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.

mark_t gravatar imagemark_t ( 2016-09-28 04:56:08 +0200 )edit

Thanks a lot ... mark_t

It's exactly what i needed..

ago_med gravatar imageago_med ( 2016-09-30 01:04:50 +0200 )edit

@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.

mark_t gravatar imagemark_t ( 2016-09-30 22:42:36 +0200 )edit

Ok... Thanks....

ago_med gravatar imageago_med ( 2016-09-30 23:01:15 +0200 )edit

2 Answers

Sort by » oldest newest most voted

answered 2016-09-28 04:52:52 +0200

mark_t gravatar image

updated 2016-09-30 20:19:28 +0200

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
edit flag offensive delete link more

answered 2016-09-30 01:04:19 +0200

ago_med gravatar image

Thanks a lot ... mark_t

It's exactly what i needed..

edit flag offensive delete link more


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.

mark_t gravatar imagemark_t ( 2016-09-30 04:04:07 +0200 )edit
Login/Signup to Answer

Question Tools


Asked: 2016-09-26 20:56:55 +0200

Seen: 404 times

Last updated: Sep 30 '16