-1

I use this code to replace text in word file its work fine in Microsoft Office but have not work on Libre office writer'

Private Sub CommandButton1_Click()

Dim AppWord As Word.Application

Set AppWord = GetObject(, "Word.Application")

AppWord.Activate

Options.DefaultHighlightColorIndex = wdNoHighlight

With ActiveDocument.Range.Find

      .Text = rep.TextBox1.Value
      .Replacement.Text = rep.TextBox2.Value
      .Replacement.ClearFormatting
      .Replacement.Font.Italic = False
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      .Execute Replace:=wdReplaceAll
    End With
    rep.Hide
End Sub    
braX
  • 11,506
  • 5
  • 20
  • 33

1 Answers1

1

No real experience, really. But OO and LO incorporate (limited) direct support for VBA (language and office object model). This is used with MS native file formats automatically. In ODF/ODS files you have to enable VBA support at the beginning of the macro, otherwise it expects LO-Basic:

Option VBASupport 1
Option Compatible

But be prepared for difficulties. And keep in mind that LO does not store its own macros in MS office file formats. Conversion to the LO-Basic and UNO object model have to be done by hand, although there is a simple online converter from business-spreadsheets.com.

Reply to your comment :

In your case, I think just put : Option VBASupport 1 to enable VBA support at the beginning above your first Sub by Libre Office. You can find more information here

Julien J
  • 2,826
  • 2
  • 25
  • 28