On MS works fine…?
Just a reminder - you are using LibreOffice and this isn’t a no-cost clone of a well-known product from Redmond
The VBA #If...Then/#Else/#End If
directives are not supported and apparently ignored, hence the duplicated definition of hwndOwner
here.