Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Delete Style using OrganizerDelete method

Posted on 2008-10-13
3
Medium Priority
?
342 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 2000 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 Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Suggested Courses

886 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