[Solved] Convert code created in MS Office to work on AOO

Creating a macro - Writing a Script - Using the API

[Solved] Convert code created in MS Office to work on AOO

Postby KingTamo » Sun Nov 19, 2017 7:54 am

Hello everyone

I am totally new in this forum and I have a problem ..
I have created a VBA code for MS Excel and when I send it to a friend he told me that he is using OpenOffice
This is the code
Code: Select all   Expand viewCollapse view
Sub Test()
    Dim fi As Integer
    Dim fo As Integer
    Dim si As String
    Dim ai() As String
    Dim i As Long
    fi = FreeFile
    Open "Sample.txt" For Input As #fi
    fo = FreeFile
    Open "Output.txt" For Output As #fo
    Do While Not EOF(fi)
        Line Input #fi, si
        ai = Split(si)
        If UBound(ai) Mod 2 = 0 Then
            ReDim Preserve ai(UBound(ai) + 1)
        End If
        For i = 0 To UBound(ai) Step 2
            Print #fo, ai(i) & " " & ai(i + 1)
        Next i
    Loop
    Close #fi
    Close #fo
End Sub

It creates a text file and split the content of the input text file to each two words in line and the results would be put in another new text file named "Output"

Is it possible to convert it to work in OpenOffice?
If possible please give me the steps in details

Thanks advanced for help
Last edited by Hagar Delest on Fri Nov 24, 2017 9:21 am, edited 1 time in total.
Reason: tagged solved.
OpenOffice 3.1 on Windows Vista
KingTamo
 
Posts: 4
Joined: Sun Nov 19, 2017 7:49 am

Re: Convert code created in MS office to work on OpenOffice

Postby Zizi64 » Sun Nov 19, 2017 8:58 am

Is it possible to convert it to work in OpenOffice?



Yes, it possible to convert your code. You need manually rework it. (You must rewrite your code based on the API functions of the Apache OpenOffice or the LibreOffice. you can use one of supported programming languages of the AOO or LO, for example the embedded StarBasic. API: Application Programming Interface.)

In other word:
You and your friend can try your code in LibreOffice: it has higher compatibility with the foreign file formats and with tho MS VBA. Maybe it will work in LO without any changing, or maybe you must insert only some extra lines at the begin of the code. See the Options in these topics:
https://forum.openoffice.org/en/forum/v ... 20&t=56522
https://forum.openoffice.org/en/forum/v ... 45&t=89411
Last edited by Zizi64 on Sun Nov 19, 2017 9:29 am, edited 3 times in total.
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.7 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.3 and AOO4.1.4
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 6083
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Convert code created in MS office to work on OpenOffice

Postby Zizi64 » Sun Nov 19, 2017 9:06 am

If possible please give me the steps in details


1.: Download, read and study Andrew Pitonyak's free macro books.
2.: Study the desctiptions of the API.
3.: Search, study and try it the attached sample codes of the macro related topics in this Forum.
4.: Then (maybe) you will able to rewrite your code for Apache OpenOffice or LibreOffice.
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.7 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.3 and AOO4.1.4
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 6083
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Convert code created in MS office to work on OpenOffice

Postby KingTamo » Sun Nov 19, 2017 1:58 pm

Thanks a lot for reply
Forgive me as I am totally newbie

I have enabled macros in OpenOffice and when trying to execute I encountered red error part for the string in this line

Code: Select all   Expand viewCollapse view
Open "YourTextFile.txt" For Input As #fi



How can I put the quotation for strings?
OpenOffice 3.1 on Windows Vista
KingTamo
 
Posts: 4
Joined: Sun Nov 19, 2017 7:49 am

Re: Convert code created in MS office to work on OpenOffice

Postby KingTamo » Sun Nov 19, 2017 2:32 pm

After many tries I could figure it out (It seems that I have to write the full path)
Code: Select all   Expand viewCollapse view
Option VBASupport 1

Sub Split_My_Text_File()
    Dim si          As String
    Dim ai()        As String
    Dim fi          As Integer
    Dim fo          As Integer
    Dim i           As Long
   
   DummyTxt=thisworkbook.path & "\YourTextFile.txt"
   
    fi = FreeFile
    Open DummyTxt For Input as #fi
    fo = FreeFile
    Open thisworkbook.path & "\Output.txt" For Output As #fo

    Do While Not EOF(fi)
        Line Input #fi, si
        ai = Split(si)
        If UBound(ai) Mod 2 = 0 Then
            ReDim Preserve ai(UBound(ai) + 1)
        End If
        For i = 0 To UBound(ai) Step 2
            Print #fo, ai(i) & " " & ai(i + 1)
        Next i
    Loop

    Close #fi
    Close #fo
   
    MsgBox "Done", 64
End Sub
OpenOffice 3.1 on Windows Vista
KingTamo
 
Posts: 4
Joined: Sun Nov 19, 2017 7:49 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 12 guests