Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-19-2024, 11:31 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: 263
RRB is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 03-20-2024, 01:25 AM
gmaxey gmaxey is offline Looking for macro Windows 10 Looking for macro Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 03-20-2024, 01:39 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: 263
RRB is on a distinguished road
Default

>> 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
Reply With Quote
  #4  
Old 03-20-2024, 01:59 AM
gmaxey gmaxey is offline Looking for macro Windows 10 Looking for macro Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 03-20-2024, 02:08 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: 263
RRB is on a distinguished road
Default

>>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
Reply With Quote
  #6  
Old 03-20-2024, 02:46 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: 263
RRB is on a distinguished road
Default

>>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
Reply With Quote
  #7  
Old 03-20-2024, 04:05 AM
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: 3,977
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

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
Reply With Quote
  #8  
Old 03-20-2024, 04: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: 263
RRB is on a distinguished road
Angry

Quote:
Originally Posted by Guessed View Post
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
I stand reprimanded and will in the future try to provide more information about any pre-post research.

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...
Reply With Quote
  #9  
Old 04-01-2024, 11:11 AM
TessaMurillo TessaMurillo is offline Looking for macro Windows Vista Looking for macro Office 2010
Advanced Beginner
 
Join Date: Mar 2024
Posts: 33
TessaMurillo has a little shameless behaviour in the past
Default

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!
Reply With Quote
Reply



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 10:24 PM.


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