Solved

Delete Style using OrganizerDelete method

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 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

19 Experts available now in Live!

Get 1:1 Help Now