Creating a macro - Writing a Script - Using the API


Postby BubikolRamios » Wed Jul 04, 2018 7:57 am

This replaces text as desired, simultaneously I want to replaced text becomes BOLD (and in next loop BOLD to be skipped). Does not work for some reason.
Replaces text, no effect on style.

Code: Select all   Expand viewCollapse view
For i= Lbound(matrix,1) To Ubound(matrix,1)
     oReplace.SearchString = matrix(i)(0)          ' Regular expression. Match any text
     oReplace.ReplaceString =  matrix(i)(1)           'Note the & places the found text back
    ' msgbox ( matrix(i)(0))
    ' oReplace.SearchRegularExpression=False  Use regular expressions
    oReplace.searchStyles=True             'We want to search styles
    REM This is the attribute to find
    SrchAttributes(0).Name = "CharWeight"
    SrchAttributes(0).Name = "CharStyleName"
    SrchAttributes(0).Value =com.sun.star.awt.FontWeight.NORMAL' tryed DONTKNOW, no difference

    REM This is the attribute to replace it with
    ReplAttributes(0).Name = "CharWeight"
    ReplAttributes(0).Name = "CharStyleName"
    ReplAttributes(0).Value =com.sun.star.awt.FontWeight.BOLD

    REM Set the attributes in the replace descriptor
     oReplace.searchAll=True               ' Do the entire document
  Next i

OPen office 4.1.5/ win 7
Posts: 39
Joined: Sat Jan 04, 2014 1:28 pm

Re: writer/ReplAttributes

Postby Zizi64 » Thu Jul 05, 2018 6:58 am

My opinion:
It is better to use the styles (Paragraph Styles, Character Styles and others) instead of the usage of a macro code to change some manually adjusted properties in a document.
Tibor Kovacs, Hungary; LO4.4.7, LO6.1.5 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.1 and AOO4.1.5
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Posts: 7769
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 2 guests