#1
|
||||
|
||||
Looking for macro
Does anyone know if there is a macro that would:
Build a table of all the texts of a given heading in the current doc with the page they are on in the adjacent column. Thank you and have a good day! Susan Flamingo |
#2
|
|||
|
|||
Yes I am sure that such a macro exists, or could be written. We (or at least most of the regulars) are not here as a free macro writing service. We are here to help others learn VBA. You have made no apparent effort write this procedure yourself or search for one online.
This should get you started: Code:
Sub ScratchMacro() 'A basic Word Macro coded by Gregory K. Maxey Dim oRng As Range Set oRng = ActiveDocument.Range With oRng.Find .Style = "Heading 2" While .Execute MsgBox oRng.Text & oRng.Information(wdActiveEndPageNumber) Wend End With lbl_Exit: Exit Sub End Sub |
#3
|
||||
|
||||
>> You have made no apparent effort write this procedure yourself or search for one online.
If you get gratification from judging me unfavorably I won't take that away from you. I searched online and also asked Chat GPT for assistance but didn't find anything that actually worked. I understand that nobody is a code-writing service here. We all share our knowledge in our areas of expertise with others out of goodwill. My area of expertise is not writing VBA code. Just born that way. In my arena, I give away much more valuable time for no charge than I could imagine you do for writing code for total dummies like me. SF |
#4
|
|||
|
|||
Susan,
I am not judging you. I and many others others have shared plenty with you. If nothing else post what you have found or have tried and perhaps you will get help. In fact, I just shared with you how to 1) find a specific heading, 2) Return the text of the heading and 3) Return the page that heading appears on. Your natural next step should have been looking for (or writing yourself) code to display that data in a table vice a message box. Instead you choose to take offense. Your response reminds me of a quote by Adam Smith: "It is not from the benevolence of the butcher, the brewer, or the baker, that we expect our dinner, but from their regard to their own interest." If you continue to feel ill judged by my suggestions then from now on I will leave you and your posts to the good will of others. |
#5
|
||||
|
||||
>>I am not judging you
You incorrectly assumed that I did not do any of my own research before posting here. That was fallacious and insulting. >>Your natural next step should have been looking for (or writing yourself) code to display that data in a table vice a message box. That is exactly what I am trying to do now. >>Instead you choose to take offense. No. I just justifiably found it necessary to answer your accusations. Don't play the victim ticket. >>If you continue to feel ill-judged by my suggestions then from now on I will leave you and your posts to the goodwill of others. If you want to stop your goodwill, that is your choice. I love constructive criticism and am open to any from anybody but it should be accurate. In my line of work, I have continuously continued to help (for no charge) those who have been very obnoxious to me, but I guess I cannot demand that of others. Your help is always appreciated SF |
#6
|
||||
|
||||
>>I am not judging you
You incorrectly assumed that I did not do any of my own research before posting here. That was fallacious and insulting. >>Your natural next step should have been looking for (or writing yourself) code to display that data in a table vice a message box. That is exactly what I am trying to do now. >>Instead you choose to take offense. No. I just justifiably found it necessary to answer your accusations. Don't play the victim ticket. >>If you continue to feel ill-judged by my suggestions then from now on I will leave you and your posts to the goodwill of others. If you want to stop your goodwill, that is your choice. I love constructive criticism and am open to any from anybody but it should be accurate. In my line of work, I have continuously continued to help (for no charge) those who have been very obnoxious to me, but I guess I cannot demand that of others. Your help is always appreciated SF |
#7
|
||||
|
||||
As Ron Burgundy would say "Well that escalated quickly"
Susan, I understand where both you and Greg are coming from here and ask that you take a step back and consider that you didn't include any information about your initial searches or include those findings in your original question. So it is not surprising that someone might assume you didn't do any research before asking the question. We can only work off the information we are given. Back on the original question, I would just create a Table of Contents with that style and then convert it to a Table with tab separators
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#8
|
||||
|
||||
Quote:
Your solution makes me feel like a total idiot. How could I have overlooked it? But I was forced to live with that a while ago...Just one of those days... |
#9
|
|||
|
|||
Hi Susan!
Yes, there are several ways to automate the process of building a table with texts of a given heading in the current document. Here is some sample VBA code that may help you with this task: ```vba Sub BuildHeaderTable() Dim doc As Document Dim tbl As Table Dim para As Paragraph Dim headerText As String Dim pageNumber As Integer Dim row As Integer 'Open the current document Set doc = ActiveDocument ' Create a new table on the active sheet Set tbl = doc.Tables.Add(doc.ActiveWindow.Selection.Range, 1, 2) Hope this helps you! |
|
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 |