Solved

Delete Style using OrganizerDelete method

Posted on 2008-10-13
3
315 Views
Last Modified: 2012-06-27
Dear Experts:
below macro deletes a user-defined style using the OrganizierDelete method.

I have got a document with SEVERAL user-defined styles that all begin with A SPACE. For some specific reason I would like to delete All these user-defined styles beginning with a space.

How am I to change below code to achieve what I want?

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
Sub DelStylesSpecial()

Dim strName As String

Dim strSource As String

Dim intObject As Integer
 

strName = " UserDefinedStyle"

strSource = ActiveDocument.FullName

intObject = wdOrganizerObjectStyles
 

Application.OrganizerDelete _

Source:=strSource, _

Name:=strName, _

Object:=intObject

End Sub

Open in new window

0
Comment
Question by:AndreasHermle
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
valentpe earned 500 total points
ID: 22708894
Hi,

I adjusted Your code to delete all styles in active document beginning with a space. I was unable to test it because i can't create style beginning with a space (my Word always trims the space). But following code should work.
Try it and give feedback.

Cheers PV
Sub DelStylesSpecial()

Dim strName As String

Dim strSource As String

Dim intObject As Integer

Dim objStyle As Style
 

strSource = ActiveDocument.FullName

intObject = wdOrganizerObjectStyles

 

For Each objStyle In ActiveDocument.Styles

  strName = objStyle.NameLocal

  If Left(strName, 1) = " " Then

    Application.OrganizerDelete _

    Source:=strSource, _

    Name:=strName, _

    Object:=intObject

  End If

Next

End Sub

Open in new window

0
 

Author Comment

by:AndreasHermle
ID: 22720213
dear valentpe,

thank you very much for your quick help. Will test it tomorrow and let you know. Till then.

Regards, Andreas
0
 

Author Comment

by:AndreasHermle
ID: 22739104
valentpe:
your code is working. Thank you very much. Actually, it is only working if I adjust your code to get styles deleted that start with strings other than just a space such as "Dipl" for example (If Left(strName, 4)="Dipl" Then ...

Styles that start with a space cannot be deleted this way. I found a couple of Internet statements on that subject that confirm it. I refer to these buggy "Char" styles that Word 2002/2003 creates automatically when you apply a paragraph style to only part of a sentence or word. I have to call the "OrganizerDelete" dialog field and delete them manually. These buggy styles resist being deleted by VBA.

Since your code is working fine with all styles other than these buggy "Char-Styles" I will assign the full 500 points. Thank you, Regards, Andreas
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now