#1
|
||||
|
||||
Looking for Macro
Hi Friends!
My VBA programming days are long gone (about 25 years ago) so I am turning here for assistance I need a macro that will scan a long Word doc (including the Footnotes area) and get the text of a certain style, and copy that text to a different page with the pg# that it is on. I am sure someone has already written a macro to do this. Thanks to all IA Susan |
#2
|
||||
|
||||
A Table of Contents is specifically set up to do this but it won't show anything from the Footnote or Endnote stories.
You might be able to run a macro to inject a {Page} field at the end of the footnotes you want and then extract a copy of that text to do what you want. The presence of the additional page number would likely have an effect on pagination too. The result of that would be two separate chunks of text and it would require some fiddling to get the footnote instances interleaved with the TOC instances from the body text. If you want a macro to do this, you will need to post a sample document with the styles and footnotes you are interested in.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
||||
|
||||
Looking for Macro
Thank you for your attention.
The file is attached as instructed. The style we want to get the text of is named "MyStyle". At the end of the doc is how we would like the results displayed. Thank you again Susan |
#4
|
||||
|
||||
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
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
||||
|
||||
Wroks great
Thank you so much
Susan |
#6
|
||||
|
||||
Sorry for bothering you, but is there a way to tell this macro to only execute till the end of the current section but no more than that?
TIA Susan |
#7
|
||||
|
||||
Haven't you moved away from the Footnotes in your other threads?
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#8
|
||||
|
||||
Yes you are correct. Thank you for thinking about me more than myself. So I need this exact macro, not in FN area, but in main text area but only to to the end of the current section
Susan |
#9
|
||||
|
||||
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 |
#10
|
||||
|
||||
Works great!
Forever thankful! |
#11
|
||||
|
||||
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 |
#12
|
||||
|
||||
Why do you need step one when the last part of step two is remove that text?
Why does it matter what character style is applied to the TC field? It is hidden text and a TC field so the style won't be visible anyway.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#13
|
||||
|
||||
I need to apply this style because, in the final book, I want all these texts that are formatted with this style to become captions in the margin. I have a friend who has programmed an add-in for Word to scan the doc for a given style and to take the texts of those instances and create margin captions exactly where they're positioned.
But I also need them for my TOC for each chapter. So hence the two steps. Thank you Susan |
#14
|
||||
|
||||
I was actually able to do this myself, with a little assistance of recording a macro:
Dim MyText As String MyText = Selection.Text Selection.Style = ActiveDocument.Styles("MyStyle") Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="TC """ & MyText & """ \l 3 ", PreserveFormatting:=False Would you believe it actually works?! I guess I am on my way to becoming the world's biggest expert in Word macros. I have in the past actually written thousands of lines of code (Pascal, remember that?) but my meds have totally zapped my memory Thank You again! Susan Flamingo |
#15
|
||||
|
||||
Hi - it is me here again to bother you. Hope you are not getting sick of me...
The document I am doing my scholarly work on is in Hebrew. In Hebrew we use many acronyms that are designated as such with double quotes in them. So 'Washington District of Columbia' would equal out to 'Washington D"C' Now these quotes are going to disqualify the whole TC field and it will not be picked up in the TOC field. So we have to replace it like this: Washington D/"C And then it works. So I need to scan the selected text before it is inserted by the above macro that I wrote and see if there are quotes in the middle of a word they should be replaced with ' /" ' and only then inserted into the TC field. This is over my small programming head. Could you help me? Thanks again Susan |
|
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 |
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 |
Macro Question: Need help making a macro to highlight the first word in every sentence | LadyAna | Word | 1 | 12-06-2014 10:39 PM |