Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Delete Style using OrganizerDelete method

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

839 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