OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

macro to delete styles from document

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Gabor
Super User
Super User


Joined: 21 Sep 2003
Posts: 610
Location: Hungary (E-Europe)

PostPosted: Fri Apr 29, 2005 5:09 pm    Post subject: macro to delete styles from document Reply with quote

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
View user's profile Send private message
probe1
Moderator
Moderator


Joined: 18 Aug 2004
Posts: 2560
Location: Chonburi Thailand Asia

PostPosted: Sat Apr 30, 2005 5:30 am    Post subject: Reply with quote

Hi Gabor,

that's not difficult Smile

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
View user's profile Send private message Visit poster's website
Gabor
Super User
Super User


Joined: 21 Sep 2003
Posts: 610
Location: Hungary (E-Europe)

PostPosted: Sat Apr 30, 2005 7:44 am    Post subject: Paragraph styles gone Reply with quote

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. Crying or Very sad
Thanks again.
Gabor
Back to top
View user's profile Send private message
Gabor
Super User
Super User


Joined: 21 Sep 2003
Posts: 610
Location: Hungary (E-Europe)

PostPosted: Sat Apr 30, 2005 1:34 pm    Post subject: happy to report Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group