Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-15-2021, 11:53 AM
JingleBelle JingleBelle is offline Update Heading Styles Linked to List Gallery Windows 10 Update Heading Styles Linked to List Gallery Office 2016
Novice
Update Heading Styles Linked to List Gallery
 
Join Date: Nov 2020
Posts: 18
JingleBelle is on a distinguished road
Default Update Heading Styles Linked to List Gallery

Frequently, I need to update the heading styles in many documents. Instead of opening each file, updating the styles, resaving, etc., I thought I could use Macropod’s recently posted code https://www.msofficeforums.com/word-...es-folder.html to update said styles.

It works beautifully except for Headings 1 through 9, which are linked to a list gallery (Outline Number Gallery). For these, the text of the heading updates as needed; however, the linked list level number does not. I am stumped but hopeful someone, here, will take a look and tell me how to correct the code. Following is my attempt to update just the Heading 1 style. I'm thinking if I can get this code to work correctly, I can use it moving forward to update Headings 2 through 9.

Code:
Sub UpdateFolderStyles()

Application.ScreenUpdating = False
Dim strDocNm As String, strFolder As String, strFile As String
Dim wdDoc As Document
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
strDocNm = ThisDocument.FullName
While strFile <> ""
  If strFolder & "\" & strFile <> strDocNm Then
    Set wdDoc = Documents.Open(Filename:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    
    With wdDoc
      .Styles("Heading 1").Font.Name = "Arial"
      .Styles("Heading 1").Font.Size = 14
      
       With ListGalleries(wdOutlineNumberGallery).ListTemplates(1).ListLevels(1)
        .NumberFormat = "%1."
        .TrailingCharacter = wdTrailingTab
        .NumberStyle = wdListNumberStyleArabic
        .NumberPosition = InchesToPoints(0)
        .Alignment = wdListLevelAlignLeft
        .TextPosition = InchesToPoints(0.33)
        .TabPosition = InchesToPoints(0.33)
        .ResetOnHigher = 0
        .StartAt = 1
        With .Font
            .Bold = True
            .Color = wdBlack
            .Size = 14
            .Name = "Arial Bold"
        End With
        .LinkedStyle = "Heading 1"
    End With
      .Close SaveChanges:=True
    End With
  End If
  strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function

Reply With Quote
  #2  
Old 06-15-2021, 03:18 PM
macropod's Avatar
macropod macropod is offline Update Heading Styles Linked to List Gallery Windows 10 Update Heading Styles Linked to List Gallery Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The code in the linked thread has nothing to do with updating Styles. There are various ways of doing that. One is to set the document's 'automatically update Styles' property, so that whatever Styles it uses will be auto-updated to match those of the document's template. Another is to use the Organizer. Both can be done in code.

For a stand-alone Style copier that uses the Organizer, see: https://www.msofficeforums.com/28497-post34.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-15-2021, 03:53 PM
JingleBelle JingleBelle is offline Update Heading Styles Linked to List Gallery Windows 10 Update Heading Styles Linked to List Gallery Office 2016
Novice
Update Heading Styles Linked to List Gallery
 
Join Date: Nov 2020
Posts: 18
JingleBelle is on a distinguished road
Default

Hey, Macropod,

Thank you for the suggestions and for the Style Copier utility. I'm looking forward to trying that out. Thanks also for taking the time to review and respond to my question. I appreciate that very much.

-JB
Reply With Quote
  #4  
Old 06-16-2021, 04:57 AM
JingleBelle JingleBelle is offline Update Heading Styles Linked to List Gallery Windows 10 Update Heading Styles Linked to List Gallery Office 2016
Novice
Update Heading Styles Linked to List Gallery
 
Join Date: Nov 2020
Posts: 18
JingleBelle is on a distinguished road
Default

The Style Copier utility is fantastic. I can easily update styles in several documents at once. Thank you for sharing!

-JB
Reply With Quote
Reply

Tags
all files in folder, list level numbering, styles

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Built in Heading Style are actually linked styles. Why? Mr Freeze Word 7 10-10-2019 07:57 AM
Keeping or restoring "Start at" value for heading list after updating styles from a template WordUser789 Word VBA 9 04-15-2019 12:16 AM
how to not add styles to style gallery when pasting text usrqsts Word 9 03-04-2016 11:41 AM
Update Heading Styles Linked to List Gallery Word 2013: My custom table styles disappeared from Gallery sinz54 Word Tables 1 03-13-2015 05:02 PM
Update Heading Styles Linked to List Gallery Heading styles come "unlinked" from Multi-level list levels after save. spthomas Word 3 11-27-2013 03:55 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:28 PM.


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