Ask Your Question

Is there a macro for Writer which can find italic text in a particular style? [closed]

asked 2015-03-18 04:11:53 +0100

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Can someone point me to or provide a macro which can go through a Writer document and select all italic text in a particular named paragraph style?



edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-08-17 17:43:08.364259

1 Answer

Sort by » oldest newest most voted

answered 2015-03-18 09:06:46 +0100

JohnSUN gravatar image

updated 2015-03-18 10:37:50 +0100

karolus gravatar image

I'm not sure that I clearly understand your question

Sub RemoveItalic
Dim oSearch  As Variant ' Search Descriptor'
Dim oFound As Variant   ' All Results of findAll'
Dim SrchAttributes(0) As New
Dim oFRange As Variant  ' One range with CharPosture=ITALIC'
Dim i&
    oSearch = ThisComponent.createSearchDescriptor()
    oSearch.SearchString = ".*"           'Regular expression. Match any text'
    oSearch.SearchRegularExpression=True  'Use regular expressions'
REM This is the attribute to find
    SrchAttributes(0).Name = "CharPosture"
    oFound = ThisComponent.findAll(oSearch) 
    If not IsNull(oFound) Then
    For i = 0 To oFound.getCount()-1
    oFRange = oFound.getByIndex(i)
    oFRange.CharStyleName = "eItal" ' For example - set for Italic chars style with name eItal...'
    Next i
End Sub
edit flag offensive delete link more


@JohnSUN: just added some 'singleQuotes' for proper Code-Hightlighting

karolus gravatar imagekarolus ( 2015-03-18 10:40:44 +0100 )edit

Sorry, I just didn't have time to do it - have distracted here, in the office :-(

JohnSUN gravatar imageJohnSUN ( 2015-03-18 11:24:40 +0100 )edit

Many thanks for this What I need is to give italics a particular character style ONLY when they appear in a paragraph with a particular paragraph style. I've modified the macro to do this by adding an If statement

 if oFRange.ParaStyleName = "Sub1" Then
    oFRange.CharStyleName = "Sub + italic" 

which seems to do the trick. This macro will save me a great deal of work.


jonjermey gravatar imagejonjermey ( 2015-03-18 20:52:38 +0100 )edit

Question Tools

1 follower


Asked: 2015-03-18 04:11:53 +0100

Seen: 679 times

Last updated: Mar 18 '15