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


Joined: 03 Feb 2006 Posts: 562
|
Posted: Thu Feb 09, 2006 6:34 am Post subject: Deleting All Custom Unused Styles [Solved] |
|
|
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 |
|
 |
Gabor Super User

Joined: 21 Sep 2003 Posts: 610 Location: Hungary (E-Europe)
|
|
| Back to top |
|
 |
Westland Super User


Joined: 03 Feb 2006 Posts: 562
|
Posted: Thu Feb 09, 2006 7:49 am Post subject: |
|
|
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 |
|
 |
probe1 Moderator


Joined: 18 Aug 2004 Posts: 2478 Location: Chonburi Thailand Asia
|
Posted: Thu Feb 09, 2006 2:46 pm Post subject: |
|
|
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 |
|
 |
Westland Super User


Joined: 03 Feb 2006 Posts: 562
|
Posted: Fri Feb 10, 2006 9:51 am Post subject: |
|
|
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 |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8995 Location: Lexinton, Kentucky, USA
|
Posted: Sat Feb 11, 2006 7:45 am Post subject: |
|
|
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 |
|
 |
Westland Super User


Joined: 03 Feb 2006 Posts: 562
|
Posted: Sat Feb 11, 2006 9:54 am Post subject: |
|
|
JohnV
Thank You ! Excellent ! _________________ "Do one thing every day that scares you" |
|
| Back to top |
|
 |
Hagar Delest Super User


Joined: 06 Feb 2006 Posts: 5167 Location: France
|
Posted: Thu Aug 03, 2006 10:07 pm Post subject: |
|
|
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 |
|
 |
AlanDavidson OOo Advocate

Joined: 09 Mar 2006 Posts: 252
|
Posted: Sun Oct 01, 2006 1:31 am Post subject: |
|
|
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 |
|
 |
Hagar Delest Super User


Joined: 06 Feb 2006 Posts: 5167 Location: France
|
|
| Back to top |
|
 |
AlanDavidson OOo Advocate

Joined: 09 Mar 2006 Posts: 252
|
Posted: Mon Oct 02, 2006 1:52 am Post subject: |
|
|
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 |
|
 |
Hagar Delest Super User


Joined: 06 Feb 2006 Posts: 5167 Location: France
|
Posted: Mon Oct 02, 2006 3:30 am Post subject: |
|
|
Do you use it for a text document ? For me, it works fine. _________________ Now on the EN user community forum |
|
| Back to top |
|
 |
AlanDavidson OOo Advocate

Joined: 09 Mar 2006 Posts: 252
|
Posted: Mon Oct 02, 2006 6:31 am Post subject: |
|
|
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 |
|
 |
Hagar Delest Super User


Joined: 06 Feb 2006 Posts: 5167 Location: France
|
Posted: Mon Oct 02, 2006 6:52 am Post subject: |
|
|
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 |
|
 |
AlanDavidson OOo Advocate

Joined: 09 Mar 2006 Posts: 252
|
Posted: Mon Oct 02, 2006 7:23 am Post subject: |
|
|
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 |
|
 |
|
|
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
|