Deleting Styles From Organizer

J

jerem

I am directly formatting paragraphs using Ctrl m (changing indents), Ctrl t
(changing tabbing), Ctrl i, Ctrl b, (font formatting) and Ctrl 1, 2 and 3 for
paragraph after settings, etc., etc. After setting up all the formatting I
create a new style – Cs – which now incorporates all that formatting into the
actual style formatting. I then use the following macro to now make all of
these formatting attributes to be incorporated into a pre-existing style
which has attributes I don't want but which I have to use (company protocol).
[I use the direct formatting because it's faster and easier than navigating
through all the Style settings and you have the visual of what the paragraph
looks like right in front of you]. The code works nicely sometimes and other
times I get a runtime error 4194 and when you go into Debug it is halting on
the OrganizerDelete statement. What I’ve done is copied that statement into
a new macro all by itself. I then create the Cs style and know it is there
in the Organizer (though it may not be in use in the document and maybe this
is what’s creating a problem????), yet when I run this new macro it will not
delete the style from the Organizer. So, in essence I need to have a
statement that will delete Cs in the Organizer regardless of whether the
style is being used in the document. Anybody have a solution. Thanks for
your help.

Sub CopyAttributesOfStyle()
'ShortcutKey = F12
Const Error_StyleDoesNotExist = 5941
Dim t As Style, s As Style
Dim trgStyleName As String
trgStyleName = InputBox("Enter the name of the style to create")
Set s = ActiveDocument.Styles("Cs")
On Error Resume Next
Set t = ActiveDocument.Styles(trgStyleName)
If Err.Number = Error_StyleDoesNotExist Then
MsgBox "The style specified does not exist."
GoTo Done
End If
On Error GoTo 0
With t
.BaseStyle = "Normal"
.ParagraphFormat = s.ParagraphFormat
.Font = s.Font
.LanguageID = s.LanguageID
End With
Selection.Style = trgStyleName

Application.OrganizerDelete Source:=ActiveDocument, Name:="Cs", Object:= _
wdOrganizerObjectStyles
Done:
Set s = Nothing
Set t = Nothing
End Sub
 
L

Larry Sulky

I am directly formatting paragraphs using Ctrl m (changing indents), Ctrlt
(changing tabbing), Ctrl i, Ctrl b, (font formatting) and Ctrl 1, 2 and 3for
paragraph after settings, etc., etc.  After setting up all the formatting I
create a new style – Cs – which now incorporates all that formatting into the
actual style formatting.  I then use the following macro to now make all of
these formatting attributes to be incorporated into a pre-existing style
which has attributes I don't want but which I have to use (company protocol).
 [I use the direct formatting because it's faster and easier than navigating
through all the Style settings and you have the visual of what the paragraph
looks like right in front of you].  The code works nicely sometimes andother
times I get a runtime error 4194 and when you go into Debug it is haltingon
the OrganizerDelete statement.  What I’ve done is copied that statement into
a new macro all by itself.  I then create the Cs style and know it is there
in the Organizer (though it may not be in use in the document and maybe this
is what’s creating a problem????), yet when I run this new macro it will not
delete the style from the Organizer.  So, in essence I need to have a
statement that will delete Cs in the Organizer regardless of whether the
style is being used in the document.  Anybody have a solution.  Thanks for
your help.

Sub CopyAttributesOfStyle()
'ShortcutKey = F12
    Const Error_StyleDoesNotExist = 5941
    Dim t As Style, s As Style
    Dim trgStyleName As String
    trgStyleName = InputBox("Enter the name of the style to create")
    Set s = ActiveDocument.Styles("Cs")
    On Error Resume Next
    Set t = ActiveDocument.Styles(trgStyleName)
    If Err.Number = Error_StyleDoesNotExist Then
        MsgBox "The style specified does not exist."
        GoTo Done
    End If
    On Error GoTo 0
    With t
        .BaseStyle = "Normal"
        .ParagraphFormat = s.ParagraphFormat
        .Font = s.Font
        .LanguageID = s.LanguageID
    End With
    Selection.Style = trgStyleName

    Application.OrganizerDelete Source:=ActiveDocument, Name:="Cs", Object:= _
        wdOrganizerObjectStyles
Done:
    Set s = Nothing
    Set t = Nothing
End Sub

Give the name of the active document:

Application.OrganizerDelete Source:=ActiveDocument.FullName,
Name:="Cs", Object:= _
wdOrganizerObjectStyles

--larry
 
J

jerem

I want to use this feature on any document that I'm in that I have to format
paragraphs for (which may be several paragraphs in the same document).
Becomes tedious to have to specify a name every time I want to use the macro.
Any way of getting around having to specify the name of the document. Just
curious why ActiveDocument is not sufficient?


Larry Sulky said:
I am directly formatting paragraphs using Ctrl m (changing indents), Ctrl t
(changing tabbing), Ctrl i, Ctrl b, (font formatting) and Ctrl 1, 2 and 3 for
paragraph after settings, etc., etc. After setting up all the formatting I
create a new style – Cs – which now incorporates all that formatting into the
actual style formatting. I then use the following macro to now make all of
these formatting attributes to be incorporated into a pre-existing style
which has attributes I don't want but which I have to use (company protocol).
[I use the direct formatting because it's faster and easier than navigating
through all the Style settings and you have the visual of what the paragraph
looks like right in front of you]. The code works nicely sometimes and other
times I get a runtime error 4194 and when you go into Debug it is halting on
the OrganizerDelete statement. What I’ve done is copied that statement into
a new macro all by itself. I then create the Cs style and know it is there
in the Organizer (though it may not be in use in the document and maybe this
is what’s creating a problem????), yet when I run this new macro it will not
delete the style from the Organizer. So, in essence I need to have a
statement that will delete Cs in the Organizer regardless of whether the
style is being used in the document. Anybody have a solution. Thanks for
your help.

Sub CopyAttributesOfStyle()
'ShortcutKey = F12
Const Error_StyleDoesNotExist = 5941
Dim t As Style, s As Style
Dim trgStyleName As String
trgStyleName = InputBox("Enter the name of the style to create")
Set s = ActiveDocument.Styles("Cs")
On Error Resume Next
Set t = ActiveDocument.Styles(trgStyleName)
If Err.Number = Error_StyleDoesNotExist Then
MsgBox "The style specified does not exist."
GoTo Done
End If
On Error GoTo 0
With t
.BaseStyle = "Normal"
.ParagraphFormat = s.ParagraphFormat
.Font = s.Font
.LanguageID = s.LanguageID
End With
Selection.Style = trgStyleName

Application.OrganizerDelete Source:=ActiveDocument, Name:="Cs", Object:= _
wdOrganizerObjectStyles
Done:
Set s = Nothing
Set t = Nothing
End Sub

Give the name of the active document:

Application.OrganizerDelete Source:=ActiveDocument.FullName,
Name:="Cs", Object:= _
wdOrganizerObjectStyles

--larry
.
 

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