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

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?



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

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

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

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.