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

Deleting All Custom Unused Styles [Solved]
Goto page 1, 2  Next
 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Writer
View previous topic :: View next topic  
Author Message
Westland
Super User
Super User


Joined: 03 Feb 2006
Posts: 562

PostPosted: Thu Feb 09, 2006 6:34 am    Post subject: Deleting All Custom Unused Styles [Solved] Reply with quote

quote from: http://oooauthors.org/en/authors/userguide2/published/

Quote:
It is not possible to delete OOo’s predefined styles from a document or template, even if they are not in use. However, custom styles can be deleted.


Sometimes, when importing Word documents, I get a lot of unused syles (I change them to the syles I want).

Is there an easy way to "purge" the unused custom styles ?
_________________
"Do one thing every day that scares you"


Last edited by Westland on Sat Feb 11, 2006 9:54 am; edited 2 times in total
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: Thu Feb 09, 2006 7:23 am    Post subject: use this Reply with quote

http://www.winnirohr.de/ooo/makros/writer_deleteWWStyles.sxw

The site itself is:
http://www.winnirohr.de/ooo/makros/index.html
Back to top
View user's profile Send private message
Westland
Super User
Super User


Joined: 03 Feb 2006
Posts: 562

PostPosted: Thu Feb 09, 2006 7:49 am    Post subject: Reply with quote

To Gabor:

Thank you. This macro solves 80% of the problems.

Quote:
deleteWWStyles
This macro will remove all styles “WW" in a Word document opened by OOo.
Deleted styles will re-appear when saving as Word's *.doc and opening again.


The macro deletes the custom styles which name starts with "WW-" (in general, the styles created when importing word docs use similar names)

I assume, form your answer, that there is no easy way to delete the remaning 20% of the unused syles, like "Heading 1 + Arial 14 pt", and so on...
_________________
"Do one thing every day that scares you"
Back to top
View user's profile Send private message
probe1
Moderator
Moderator


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

PostPosted: Thu Feb 09, 2006 2:46 pm    Post subject: Reply with quote

Look at the code.
Identify the
Code:

 ' begin with string

IF condition.

Comment out the IF and the END IF line (by adding a REM at beginning of the line), voila.

Testing here delted all deletable styles.
Good luck.
_________________
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
Westland
Super User
Super User


Joined: 03 Feb 2006
Posts: 562

PostPosted: Fri Feb 10, 2006 9:51 am    Post subject: Reply with quote

To probe1:

Quote:
Look at the code.
Identify the

Code:

' begin with string


IF condition.

Comment out the IF and the END IF line (by adding a REM at beginning of the line), voila.

Testing here delted all deletable styles.


You are rigth ! This macro will delete all custom syles !!!
The only problem is that I only want to delete the unused custom syles !
On the Stylist Window you can filter the viewed syles, to see only the used styles. It should be possible to access this property, to prevent a macro from deleting the used styles.

I don't have the required expertise to do that. Any volunteers ?
_________________
"Do one thing every day that scares you"
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Sat Feb 11, 2006 7:45 am    Post subject: Reply with quote

This should do what you want. It seems to be a heavy handed way to do so but I can't find the property of a paragraph style that indicates either that it is active in the document or that it is a custom style. I would think one or both might be available and fear I've just missed something.

EDIT: Macro updated Aug. 3, 2006.
EDIT: This macro is out of date. The newest version which will hopefully eliminated
any errors noted in the posts below can be found at:
http://www.oooforum.org/forum/viewtopic.phtml?t=46147

Code:
Sub DeleteExcessStyles
'>>>>>>>>>>>>>USER VARIABLES<<<<<<<<<<<<<<
ShowFirstMessage = True 'Change to False to avoid 1st message.
AskDelete = True 'Change to False if you don't want to be
'asked about deleting a style.
'>>>>>>>>>>>END USER VARIABLES<<<<<<<<<<<<
Dim inUse()
oDoc = ThisComponent
If ShowFirstMessage then
 a$ = "Remove unused styles?" & chr(13) & "This will not affect OOo's predefined styles."
 If MsgBox(a$,4,"Paragraph Style Remover") = 7 then End
EndIf
PreDefined = PreDefineStyles 'Array of all predefined paragraph styles.
oEnum = oDoc.Text.createEnumeration
While oEnum.hasMoreElements
 thisElement = oEnum.nextElement
 Do
  For i = 0 to uBound(inUse())
   If inUse(i) = thisElement.ParaStyleName then Exit Do
  Next
  ReDim Preserve inUse(i)
  inUse(i) = thisElement.ParaStyleName
 Loop Until i > uBound(inUse())
Wend
'Print "Current document styles are " & Join(inUse())
oStyles = oDoc.getStyleFamilies
oParaStyles = oStyles.getByName("ParagraphStyles")
oParaStyleNames() = oParaStyles.getElementNames()
For i = 0 to uBound(oParaStyleNames)
 thisName = oParaStyleNames(i)
 Do
  For c = 0 to uBound(inUse())
   If inUse(c) = thisName then Exit Do
  Next c
  For c = 0 to uBound(PreDefined())
   If PreDefined(c) = thisName then Exit Do
  Next c
  If AskDelete then
   a$ = "Delete unused paragraph style <" & thisName & ">? "
   iAns = MsgBox(a$,3)
   If iAns = 2 then End 'Cancel button.
   If iAns = 7 then goto Skip 'No button.
  EndIf
  oParaStyles.removeByName(thisName)
  DeletedStyles = DeletedStyles & thisName & Chr(13)
  SKIP:
 Loop Until c > uBound(inUse())
Next i
If Len(DeletedStyles) = 0 then DeletedStyles = "None"
MsgBox (DeletedStyles,,"The following unused custom styles were deleted:")
End Sub

Function PreDefineStyles
aray = Array("Standard","Text body","Heading","List","Caption",_
"Index","First line indent","Hanging indent","Text body indent",_
"Salutation","Signature","List Indent","Marginalia","Heading 1",_
"Heading 2","Heading 3","Heading 4","Heading 5","Heading 6",_
"Heading 7","Heading 8","Heading 9","Heading 10","Title","Subtitle",_
"Numbering 1 Start","Numbering 1","Numbering 1 End",_
"Numbering 1 Cont.","Numbering 2 Start","Numbering 2",_
"Numbering 2 End","Numbering 2 Cont.","Numbering 3 Start",_
"Numbering 3","Numbering 3 End","Numbering 3 Cont.",_
"Numbering 4 Start","Numbering 4","Numbering 4 End",_
"Numbering 4 Cont.","Numbering 5 Start","Numbering 5",_
"Numbering 5 End","Numbering 5 Cont.","List 1 Start","List 1",_
"List 1 End","List 1 Cont.","List 2 Start","List 2","List 2 End",_
"List 2 Cont.","List 3 Start","List 3","List 3 End","List 3 Cont.",_
"List 4 Start","List 4","List 4 End","List 4 Cont.","List 5 Start",_
"List 5","List 5 End","List 5 Cont.","Index Heading","Index 1",_
"Index 2","Index 3","Index Separator","Contents Heading","Contents 1",_
"Contents 2","Contents 3","Contents 4","Contents 5",_
"User Index Heading","User Index 1","User Index 2","User Index 3",_
"User Index 4","User Index 5","Contents 6","Contents 7","Contents 8",_
"Contents 9","Contents 10","Illustration Index Heading",_
"Illustration Index 1","Object index heading","Object index 1",_
"Table index heading","Table index 1","Bibliography Heading",_
"Bibliography 1","User Index 6","User Index 7","User Index 8",_
"User Index 9","User Index 10","Header","Header left","Header right",_
"Footer","Footer left","Footer right","Table Contents","Table Heading",_
"Illustration","Table","Text","Frame contents","Footnote","Addressee",_
"Sender","Endnote","Drawing","Quotations","Preformatted Text",_
"Horizontal Line","List Contents","List Heading")
PreDefineStyles = aray
End Function


Last edited by JohnV on Sun Oct 22, 2006 2:56 pm; edited 2 times in total
Back to top
View user's profile Send private message
Westland
Super User
Super User


Joined: 03 Feb 2006
Posts: 562

PostPosted: Sat Feb 11, 2006 9:54 am    Post subject: Reply with quote

JohnV

Thank You ! Excellent !
_________________
"Do one thing every day that scares you"
Back to top
View user's profile Send private message
Hagar Delest
Super User
Super User


Joined: 06 Feb 2006
Posts: 5164
Location: France

PostPosted: Thu Aug 03, 2006 10:07 pm    Post subject: Reply with quote

Up (because the new JohnV macro version is very nice above).

Thanks so much for the bells & whistles, it works perfectly !
_________________
Now on the EN user community forum
Back to top
View user's profile Send private message
AlanDavidson
OOo Advocate
OOo Advocate


Joined: 09 Mar 2006
Posts: 252

PostPosted: Sun Oct 01, 2006 1:31 am    Post subject: Reply with quote

I use OOo 2.0.3 on WinXP Home. I tried the macro.

For the following line of code:

If inUse(i) = thisElement.ParaStyleName then Exit Do

I got the following error:

"BASIC runtime error. Property or method not found."

Can anyone help?
Back to top
View user's profile Send private message
Hagar Delest
Super User
Super User


Joined: 06 Feb 2006
Posts: 5164
Location: France

PostPosted: Sun Oct 01, 2006 11:16 pm    Post subject: Reply with quote

How have you installed the macro ?
_________________
Now on the EN user community forum
Back to top
View user's profile Send private message
AlanDavidson
OOo Advocate
OOo Advocate


Joined: 09 Mar 2006
Posts: 252

PostPosted: Mon Oct 02, 2006 1:52 am    Post subject: Reply with quote

1) Open an OOo doc.

2) Tools | Macros | Organize Macros | OpenOffice.org Basic

The "Basic Macros" dialog appears.

3) Click "Organizer".

The "Basic Macro Organizer" dialog appears.

4) In the "Modules" tab, open "My Macros".

5) Highlight "Standard".

6) Click "New".

7) Type "MyModule". Click OK.

8) Click "Edit".

The VB editor appears.

9) Paste the macro from the forum. Click "Run".

Now run the macro using Tools | Macros | Run Macro

The message box appears: "Remove unused styles?...". Click Yes

Then the error message appears as in my post.
Back to top
View user's profile Send private message
Hagar Delest
Super User
Super User


Joined: 06 Feb 2006
Posts: 5164
Location: France

PostPosted: Mon Oct 02, 2006 3:30 am    Post subject: Reply with quote

Do you use it for a text document ? For me, it works fine.
_________________
Now on the EN user community forum
Back to top
View user's profile Send private message
AlanDavidson
OOo Advocate
OOo Advocate


Joined: 09 Mar 2006
Posts: 252

PostPosted: Mon Oct 02, 2006 6:31 am    Post subject: Reply with quote

It's a text document (ODT).

I inserted a "j = j + 1" just before the failing line:

If inUse(i) = thisElement.ParaStyleName then Exit Do

If I then single step through the macro, "j" reaches a value of "669" before the error message appears.

I don't know much about macros, but this suggests that the failing line works 669 times, so it must be OK. Maybe an array bounds error?
Back to top
View user's profile Send private message
Hagar Delest
Super User
Super User


Joined: 06 Feb 2006
Posts: 5164
Location: France

PostPosted: Mon Oct 02, 2006 6:52 am    Post subject: Reply with quote

That's quite clever !!! I tried it also and it stopped at 60.
You're completely right, I replaced the inUse() declaration by
Code:
Dim inUse() as integer
and it worked (I went over 1000 iterations).
That's rather strange because inUse(i) should be a string. I put integer by mistake but it worked.
_________________
Now on the EN user community forum
Back to top
View user's profile Send private message
AlanDavidson
OOo Advocate
OOo Advocate


Joined: 09 Mar 2006
Posts: 252

PostPosted: Mon Oct 02, 2006 7:23 am    Post subject: Reply with quote

With:

Dim inUse() as string

I get 669 iterations.
----------------------------------
With:

Dim inUse() as integer

I get > 100,000 iterations.

I'm fairly sure that this is an endless loop.
----------------------------------

What do I do now? :)
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 Writer All times are GMT - 8 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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