Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-14-2023, 03:50 AM
Nirnim Nirnim is offline Delete every style in the document that isn't saved in the template Windows 11 Delete every style in the document that isn't saved in the template Office 2016
Novice
Delete every style in the document that isn't saved in the template
 
Join Date: Mar 2023
Posts: 2
Nirnim is on a distinguished road
Question Delete every style in the document that isn't saved in the template

Hello!
As the title implies, I would like to know if there's a way of creating a Macro that checks all the styles that are currently in the active document against all the styles that are saved in the template associated to the document.
I was thinking of something like this (pseudocode-ish):



Code:
Private Sub FixStyles()
    Dim stlStyle As Style
    Dim arrTemplateStyles() As Style ' This array would contain all the styles saved in the template
    ' Maybe there's a built-in collection that has these values and makes this variable unnecessary
    
    ' Iterate through all the styles in the current document
    For Each stlStyle In ActiveDocument.Styles
        ' If the style is not in the list of styles saved in the attached template
        If Not SearchInArray(stlStyle.NameLocal, arrTemplateStyles) Then
            ' Delete said style and go on with the next one
            Delete stlStyle
        End If
    Next stlTemplateStyle
End Sub

Private Function SearchInArray(strName As String, varArray As Variant) As Boolean
    ' Function used to look for a specific item in an array
    Dim blnFound As Boolean
    Dim varItem As Variant
    blnFound = False
    
    For Each varItem In varArray
        If varItem.NameLocal = strName Then
            blnFound = True
            Exit For
        End If
    Next varItem
    SearchInArray = blnEncontrado
End Function
I'm no expert in VBA, Word or anything like that, so any help or tips are welcome!
Reply With Quote
 

Tags
style, vba, word 16



Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete every style in the document that isn't saved in the template USB disconnected while document was live; saved document now corrupt. How do I retrieve document? MaxB Word 2 07-01-2019 04:42 PM
My style keeps changing, can't get saved style to apply Meenie50 Word 7 07-20-2017 03:47 PM
Keyboard shortcut or QAT button for a saved paragraph style? VeazyT Outlook 0 05-15-2017 01:38 PM
How to make a fillable word template but not see what is not req'd to be filled in saved as document sjohnstone@edgeautomation Word 1 05-02-2017 10:05 AM
Delete every style in the document that isn't saved in the template Saved style set changing ljd108 Word 1 10-21-2014 11:43 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:38 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft