How to convert VBA code to LibreOffice Basic

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Spectator
Posts: 2
Joined: Tue Jul 27, 2021 10:02 am

How to convert VBA code to LibreOffice Basic

Post by Spectator »

Good day! A very big request to help!

I don't understand anything about libreoffice BASIC language, but I need to run this macros from VBA to libreoffice. automatic converters do not work.

Help me rewrite this code!

Code: Select all

Private Sub ComboBox1_GotFocus() 
  With ActiveCell
    Me.ComboBox1.Text = .Value
    Me.ComboBox1.Top = Range("D1:D" & .Row - 1).Height + 0.75
  End With
End Sub

Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
  If KeyCode = 13 Then ActiveCell.Offset(0, 1).Select 
  If KeyCode = 27 Then Me.ComboBox1.Text = ActiveCell.Value
End Sub

Private Sub ComboBox1_LostFocus()
  With Me.ComboBox1
    .TopLeftCell.Value = .Text
    If Len(.Text) > 0 Then Call AddFIO(.Text)
  End With
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  With Me.ComboBox1
    If Target.Count > 1 Then 
      If Visible Then .Visible = False
      Exit Sub
    End If
    

    If Not Intersect(.TopLeftCell, [D8:D200]) Is Nothing Then
      If Len(.Text) > 0 And .Text <> .TopLeftCell.Text Then
        .TopLeftCell.Value = .Text
        If Len(.Text) > 0 Then Call AddFIO(.Text)
      End If
      
    End If
    
    If Not Intersect(Target, [D8:D200]) Is Nothing Then
      .Visible = True: .Activate
    Else
      If .Visible Then .Visible = False
    End If
  End With
End Sub

Private Sub AddFIO(Text As String)

  If Application.WorksheetFunction.CountIf([FIO], Text) = 0 Then
    Sheets("List").[A65536].End(xlUp).Offset(1, 0).Value = Text
    Me.ComboBox1.ListFillRange = "FIO" 
  End If
End Sub
LibreOffice 2.0
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: how to Convert VBA code to libreoffice Basic

Post by Villeroy »

How would you convert StarBasic to VBA? Read, understand, rewrite.
The language is similar. The API is radically different.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
RoryOF
Moderator
Posts: 34610
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: how to Convert VBA code to libreoffice Basic

Post by RoryOF »

What does your macro do (save us the effort of analysing it)? It is possible there is an existing equivalent macro already for OpenOffice.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Spectator
Posts: 2
Joined: Tue Jul 27, 2021 10:02 am

Re: How to convert VBA code to LibreOffice Basic

Post by Spectator »

There is a list on the second sheet. On the first sheet, when you enter several characters in the column, options from the second sheet appear.
Attachments
Screenshot_3.png
Screenshot_3.png (1.37 KiB) Viewed 3564 times
Screenshot_2.png
Screenshot_2.png (2.98 KiB) Viewed 3564 times
Screenshot_1.png
Screenshot_1.png (582 Bytes) Viewed 3564 times
LibreOffice 2.0
User avatar
RoryOF
Moderator
Posts: 34610
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: How to convert VBA code to LibreOffice Basic

Post by RoryOF »

Use Forum Search (top right of Forum window) to search for macros containing Listbox. I am certain there are on Forum macros that do what you require or nearly so.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
robleyd
Moderator
Posts: 5078
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: How to convert VBA code to LibreOffice Basic

Post by robleyd »

Perhaps Data Validation might solve your problem without involving Cthulhu macros. Search the Help - F1 - for validity.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to convert VBA code to LibreOffice Basic

Post by Villeroy »

Why a macro? Auto-complete by validation works without macros in Excel and Calc. And yes, you may also use form controls where auto-complete works without any Basic code.

And Libre/OpenOffice comes with a database component.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply