| View previous topic :: View next topic |
| Author |
Message |
Gabor Super User

Joined: 21 Sep 2003 Posts: 610 Location: Hungary (E-Europe)
|
Posted: Fri Apr 29, 2005 5:09 pm Post subject: macro to delete styles from document |
|
|
Perhaps I am not alone with my problem.
Although I have been using OOo (and formerly SO5.2) for over 3 years I still have to stick to the Windows doc format because I work with a huge number of short documents received from here and there and partly created by myself and I share documents with several others who use MS or QuarkXpress or InDesign, neither of which (or at least the versions in use) understands the OOo formats.
I try to use my own template as much as I can but my files still get fat with an enormous number of custom styles which probably come from external sources. Among them such beauties like WW-AbsatzStandardSchriftart etc. Often these terrible things intervene into my actually used styles and then ruin is added to chaos.
Each and every of them has a name which starts with WW (i.e. 2 capital Ws). Hints of WinWord?
I can delete these styles one by one but, unfortunately, loading my own ones does not delete them.
Now my humble request.
Could perhaps somebody of you who is well acquainted with writing macros create a macro which, if bound to a button or a keyboard shortcut, would eliminate from the open document all custom styles whose name begins with WW?
I am unable to do it myself because of lack of knowledge.
Maybe it would be too difficult or it would be too time-consuming for an expert in which case I do apologize for my request. |
|
| Back to top |
|
 |
probe1 Moderator


Joined: 18 Aug 2004 Posts: 2478 Location: Chonburi Thailand Asia
|
Posted: Sat Apr 30, 2005 5:30 am Post subject: |
|
|
Hi Gabor,
that's not difficult
Check this out:
| Code: |
Sub delWWStyles
iAntwort = msgbox(_
"This macro will remove all Styles ""WW-"" in an OOo-Writer document" & _
chr(13) & _
"Press YES to continue or NO to abbort deletion" ,36, "wri_delWWStyles 20050430")
if iAntwort = 7 then
exit sub
end if
' user said yes
oDok = ThisComponent
oStyles = oDok.StyleFamilies
oParaStyles = oStyles.getByName("ParagraphStyles")
' all names
asParaStyleNames() = oParaStyles.getElementNames()
for i = 0 to UBound(asParaStyleNames)
' begin with string
if Instr(1, asParaStyleNames(i) , "WW-") then
oParaStyles.removeByName( asParaStyleNames(i) )
End if
next i
End Sub |
Just a little question and they're gone.
As you see: no error checking!
Note:
Names begin (here) with a WW- so code checks for that
Deleted paragragh styles re-appear when the document is saved in doc-format and opened again (OOo conversion habit?)
HTH _________________ Cheers
Winfried
My Macros
DateTime2 extension: insert date, time or timestamp, formatted to your needs |
|
| Back to top |
|
 |
Gabor Super User

Joined: 21 Sep 2003 Posts: 610 Location: Hungary (E-Europe)
|
Posted: Sat Apr 30, 2005 7:44 am Post subject: Paragraph styles gone |
|
|
Hi Winfried,
Your macro works fine, thank you very much!
And you hit the nail on the head: these stupidities reappear. But if I have to transfer everything to, say, rtf, then first I would like to destroy all remnants of WW-things.
However, the macro does not help me to eliminate WW character styles and WW numbering styles.
Can you perhaps give me a hint what I should try to change or add in the macro? Unfortunately I cannot finf it out on my own.
Thanks again.
Gabor |
|
| Back to top |
|
 |
Gabor Super User

Joined: 21 Sep 2003 Posts: 610 Location: Hungary (E-Europe)
|
Posted: Sat Apr 30, 2005 1:34 pm Post subject: happy to report |
|
|
I am happy to report that I was able to copy and change the relevant parts of the macro and now it kills unwanted paragraph, character and numbering styles, which do not return in rtf.
Thank you again!
Gabor |
|
| Back to top |
|
 |
|