Results 1 to 5 of 5

Thread: How to check if a Word Style exists

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    If you know it always exists why do you need code to see if it exists?

     
    Sub Test()
        MsgBox StyleExists("_AG Green Highlight") 
    End Sub
     
    Function StyleExists(StyleName As String) As Boolean
        Dim MyStyle As Word.Style
        On Error Resume Next
        ' maybe this ...
        Set MyStyle = ActiveDocument.Styles(StyleName)
        ' or maybe this ...
        ' Set MyStyle = ActiveDocument.AttachedTemplate.Styles(StyleName)
        StyleExists = Not MyStyle Is Nothing
    End Function
    Last edited by Aussiebear; 02-27-2025 at 01:29 PM.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •