Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-01-2024, 07:22 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,185
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

Here is a quick and dirty method to add the TC fields. It is somewhat flawed in using Selection objects because I can't immediately see why range won't work and couldn't be bothered figuring it out. You will have problems if there are instances of MyStyle spanning multiple paragraphs.
Code:
Sub aaa()
  Dim aFN As Footnote, aRng As Range, aRngRef As Range, sCode As String, aFld As Field
  Set aRng = Selection.Range.Sections(1).Range
  With aRng.Find
    .ClearFormatting
    .Text = ""
    .Style = "MyStyle"
    Do While .Execute
      sCode = "TC """ & aRng.Text & """ \l 1 "
      aRng.Collapse wdCollapseEnd
      Set aFld = ActiveDocument.Fields.Add(Range:=aRng, Text:=sCode)
      aFld.Select
      Selection.Font.Reset
      aRng.Start = Selection.Range.End
      aRng.End = aRng.Sections(1).Range.End
    Loop
  End With
End Sub

__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #2  
Old 02-01-2024, 08:12 PM
RRB's Avatar
RRB RRB is offline Looking for Macro Windows 11 Looking for Macro Office 2021
Susan Flamingo
Looking for Macro
 
Join Date: May 2014
Location: The Holy City of Jerusalem
Posts: 301
RRB is on a distinguished road
Default

Works great!
Forever thankful!
Reply With Quote
  #3  
Old 02-06-2024, 08:17 AM
RRB's Avatar
RRB RRB is offline Looking for Macro Windows 11 Looking for Macro Office 2021
Susan Flamingo
Looking for Macro
 
Join Date: May 2014
Location: The Holy City of Jerusalem
Posts: 301
RRB is on a distinguished road
Default

I feel guilty for bothering you so much...
Could we get a macro that does simply two things:
1. format selected text with the style "MyStyle" ''I am gonna need this for later
2. Takes that text and inserts it into a TC field as level 3 ad {tc (text of selection) l 3} formatted with my myStyle and the original text is erased.

Thank you so much

Susan
Reply With Quote
Reply

Thread Tools
Display Modes


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 09:57 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