Search code examples
vbaopenoffice.org

VBA to Open Office Basic convert trouble


Hi i'm trying to rewrite\convert this code to VBScript. In Excel 2013 work perfectly but in Open Office whatever i'm trying to search is throws there is no data(Nie znaleziono danych).

VBA Code:

Sub Znajdz()

Dim szukane As Variant

szukane = InputBox("Wpisz szukane słowo", "Wyszukaj")

If szukane = "" Then
MsgBox "Nie wpisałeś nic w okienku Wyszukaj", vbOKOnly + vbExclamation,"Brak danych"
Exit Sub
End If

On Error GoTo blad

Cells.Find(What:=szukane, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
    xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
    , SearchFormat:=False).Activate

Exit Sub

blad:

MsgBox "Nie znaleziono danych", vbOKOnly + vbInformation, "Brak wyników"

End Sub

My VBScript:

Sub Znajdz()

Dim szukane As Variant

szukane = InputBox("Wpisz szukane słowo", "Wyszukaj")

If szukane = "" Then
MsgBox "Nie wpisałeś nic w okienku Wyszukaj", vbOKOnly + vbExclamation, "Brak danych"
Exit Sub
End If

On Error GoTo blad

Cells.Find(What:=szukane, After:=ActiveCell, LookIn:=-4163, LookAt:= _
    1, SearchOrder:=1, SearchDirection:=1, MatchCase:=False _
    , SearchFormat:=False).Activate

Exit Sub

blad:

MsgBox "Nie znaleziono danych", vbOKOnly + vbInformation, "Brak wyników"

End Sub

Help me i must use it in Open Office as macro


Solution

  • Open Office doesn't use VBA or VBScript for macros, it uses Open Office Basic.

    The OO Wiki gives a method for executing VBA macros; maybe worth a look?

    I've tried to convert it for you - give this a try? I don't have OO to hand so can't test that it works...

    Sub Znajdz()
    
    Dim szukane As String
    Dim oCell As Object
    dim index As long
    Dim Find As Object
    Dim oSheet As Object
    oSheet = StarDesktop.CurrentComponent.Sheets(0)
    
    szukane = InputBox("Wpisz szukane słowo", "Wyszukaj")
    
    If szukane = "" Then
        MsgBox "Nie wpisałeś nic w okienku Wyszukaj", MB_OK + MB_ICONEXCLAMATION, "Brak danych"
        End
    End If
    
    oCell = oSheet.getCellByPosition(1,1)
    index = oCell.CellAddress.Sheet
    Find = oSheet.createSearchDescriptor
    Find.setSearchString(szukane)
    oCell = oSheet.FindFirst(Find)
    If Not IsNull(oCell) Then
        MsgBox "Found it at " & oCell.CellAddress.Column & oCell.CellAddress.Row
    Else
        MsgBox "Not Found!"
    Endif
    
    End Sub