Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 10-21-2017, 02:26 PM
macropod's Avatar
macropod macropod is offline Update Styleref Fields Windows 7 64bit Update Styleref Fields Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

It's still not clear from your post whether your Headlinestyle Styles are just Heading Styles under another name. If so, try the following:
Code:
Sub IndexUpdater()
Application.ScreenUpdating = False
Dim i As Long, strStl As String, strRef As String, Rng As Range
Set Rng = Selection.Range
Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\HeadingLevel")
With Rng
  For i = 1 To .Fields.Count
    With .Fields(i)
      If .Type = wdFieldIndexEntry Then
        If .Code.Fields.Count = 1 Then
          With .Code.Fields(1)
            If .Type = wdFieldStyleRef Then
              strStl = .Code.Paragraphs(1).Style
              strRef = Split(Split(.Code.Text, "STYLEREF")(1), Chr(34))(1)
              If strRef <> strStl Then .Code.Text = Replace(.Code.Text, strRef, strStl)
            End If
          End With
        End If
      End If
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
With this code, the heading that contains the insertion point or selection, plus any subordinate headings and text. If the current selection is body text, the '\HeadingLevel' bookmark includes the preceding heading, plus any headings and text subordinate to that heading.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #17  
Old 10-22-2017, 01:24 AM
datech-hh datech-hh is offline Update Styleref Fields Windows 10 Update Styleref Fields Office 2016
Novice
Update Styleref Fields
 
Join Date: Oct 2017
Posts: 9
datech-hh is on a distinguished road
Default

Hi Paul, i cannot set the range this way, it doesn't work with our doc styles. Thanks anyway
Thomas
Reply With Quote
  #18  
Old 11-04-2017, 12:15 PM
FionaMcKenzie FionaMcKenzie is offline Update Styleref Fields Windows 10 Update Styleref Fields Office 2016
Novice
 
Join Date: Oct 2017
Location: Surrey, United Kingdom
Posts: 14
FionaMcKenzie is on a distinguished road
Default

Just a little tip with updating fields in Word. It's slow and cumbersome to loop through fields in the different text boundaries (document, headers, footers, shapes) to update fields.

The quickest way to update fields is to write a macro that does a print preview, then closes the print preview & most fields will be updated. (Except of fields that are formulas, .e.g. SUM(Above))
Reply With Quote
  #19  
Old 11-04-2017, 01:35 PM
macropod's Avatar
macropod macropod is offline Update Styleref Fields Windows 7 64bit Update Styleref Fields Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

That really doesn't have anything to do with the issue here and, in any event, I've posted macros here that do basically as you suggest, plus updating all fields in the document body which a print preview won't do). For example: https://www.msofficeforums.com/word/...html#post96856
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Styleref Fields How do I update all fields from a new input Kozzzle Word 7 10-19-2017 06:12 PM
how to update calculated fields sectionbreak Mail Merge 4 06-04-2014 12:12 AM
Macro to update fields rhatx Word VBA 0 03-02-2011 12:14 PM
VBA to update certain (but not all) fields sparkyrose Word VBA 0 05-20-2010 12:50 PM
Can no longer update fields! slindsay Word 0 09-03-2009 05:10 PM

Other Forums: Access Forums

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


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