delete style and if style not found what to do....

D

donna

i am trying to delete few style from activedocument. The macro is in one of
the template and people create new document from there. At the end of
tabulation etc. people delete unwant styles. It's always style a, b and c to
delete. The macro deletes this a, b and c style but what coding I should
write if they hit button again.
Basically, I would like to run a macro and if style is not found it should
gives a pop up saying styles are been deleted instead of run time error which
says "styles not found"

Any help
 
D

donna

Application.OrganizerDelete Source:=ActiveDocument, Name:="Abstract",
Object:=wdOrganizerObjectStyles
Application.OrganizerDelete Source:=ActiveDocument, Name:="Indent",
Object:=wdOrganizerObjectStyles
Application.OrganizerDelete Source:=ActiveDocument, Name:="Caption",
Object:=wdOrganizerObjectStyles
Application.OrganizerDelete Source:=ActiveDocument, Name:="Caption
(Cont'd)", Object:=wdOrganizerObjectStyles
Application.OrganizerDelete Source:=ActiveDocument, Name:="Center",
Object:=wdOrganizerObjectStyles
Application.OrganizerDelete Source:=ActiveDocument, Name:="hidden",
Object:=wdOrganizerObjectStyles

I'm attaching the coding.
 
J

Jean-Guy Marcil

donna was telling us:
donna nous racontait que :
Application.OrganizerDelete Source:=ActiveDocument, Name:="Abstract",
Object:=wdOrganizerObjectStyles
Application.OrganizerDelete Source:=ActiveDocument, Name:="Indent",
Object:=wdOrganizerObjectStyles
Application.OrganizerDelete Source:=ActiveDocument, Name:="Caption",
Object:=wdOrganizerObjectStyles
Application.OrganizerDelete Source:=ActiveDocument, Name:="Caption
(Cont'd)", Object:=wdOrganizerObjectStyles
Application.OrganizerDelete Source:=ActiveDocument, Name:="Center",
Object:=wdOrganizerObjectStyles
Application.OrganizerDelete Source:=ActiveDocument, Name:="hidden",
Object:=wdOrganizerObjectStyles

I'm attaching the coding.

'_______________________________________
Sub CleanUpStyles()

DeleteStyle "Caption"
DeleteStyle "Indent"
DeleteStyle "Caption"
DeleteStyle "Caption (Cont'd)"
DeleteStyle "Center"
DeleteStyle "hidden"

End Sub
'_______________________________________

'_______________________________________
Function DeleteStyle(StyleName As String)

On Error GoTo StyleDeleted
ActiveDocument.Styles(StyleName).Delete

Exit Function

StyleDeleted:
Err.Clear
MsgBox "The style """ & StyleName & """ has " _
& "already been deleted.", vbExclamation, _
"Style not in list"

End Function
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jean-Guy Marcil

Jean-Guy Marcil was telling us:
Jean-Guy Marcil nous racontait que :
donna was telling us:
donna nous racontait que :


'_______________________________________
Sub CleanUpStyles()

DeleteStyle "Caption"
DeleteStyle "Indent"
DeleteStyle "Caption"
DeleteStyle "Caption (Cont'd)"
DeleteStyle "Center"
DeleteStyle "hidden"

End Sub
'_______________________________________

'_______________________________________
Function DeleteStyle(StyleName As String)

On Error GoTo StyleDeleted
ActiveDocument.Styles(StyleName).Delete

Exit Function

StyleDeleted:
Err.Clear
MsgBox "The style """ & StyleName & """ has " _
& "already been deleted.", vbExclamation, _
"Style not in list"

End Function
'_______________________________________

Ooops..
Of course, replace the first
DeleteStyle "Caption"
with
DeleteStyle "Abstract"

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top