Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 01-30-2024, 08:39 PM
Guessed's Avatar
Guessed Guessed is offline Looking for Macro Windows 10 Looking for Macro Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

This macro works for the instances of MyStyle in the footnotes.
Code:
Sub aaa()
  Dim aFN As Footnote, aRng As Range, aRngRef As Range, sCode As String
  For Each aFN In ActiveDocument.Footnotes
    Set aRng = aFN.Range
    With aRng.Find
      .ClearFormatting
      .Text = ""
      .Style = "MyStyle"
      If .Execute Then
        Set aRngRef = aFN.Reference
        aRngRef.Collapse wdCollapseEnd
        sCode = "TC """ & aRng.Text & """ \l 1 "
        ActiveDocument.Fields.Add Range:=aRngRef, Text:=sCode
      End If
    End With
  Next aFN
  
  Set aRng = ActiveDocument.Range
  aRng.InsertParagraphAfter
  aRng.Collapse wdCollapseEnd
  sCode = "TOC \f "
  ActiveDocument.Fields.Add Range:=aRng, Text:=sCode
End Sub
However, we can't ALSO use the instances of MyStyle in the body of the document because it appears that only Paragraph Styles can be used to build a TOC with styles.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perfect macro not working when its code is inserted in larger macro RobiNew Word VBA 3 10-18-2023 03:19 AM
Macro to Remove Paras with Line Spac 6; Macro to Convert Paragraphs to Outline Numbered venganewt Word VBA 0 01-25-2022 06:28 PM
Looking for Macro Footnote extraction macro [Why is this macro so slow? / anyway to make it faster?] Le_Blanc Word VBA 10 03-22-2021 11:38 AM
Spell check macro within macro button field doesn't work in one document samuelle Word VBA 0 07-20-2016 02:27 AM
Looking for Macro Macro Question: Need help making a macro to highlight the first word in every sentence LadyAna Word 1 12-06-2014 10:39 PM

Other Forums: Access Forums

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


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