The easiest way is to use macro recording. To enable the feature, go to Tools → Options → LibreOffice → General and check “Enable experimental (unstable) features”. A new entry “Record Macro” will appear in Tools → Macros. Once you click on it, macro recording mode will start and almost everything (for more on this topic and the list of actions that are not recorded read Recording a Macro) you do while in it will be saved once you click “Stop Recording” button. You will then be asked to save newly created macro, given the choice of storing it only for the current document or being generally accessible.
If you are interested in seeing the code generated this way, open Tools → Macros → Organize Macros → LibreOffice Basic, select macro and click “Edit”.