Solved

Delete Style using OrganizerDelete method

Posted on 2008-10-13
3
323 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

735 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