Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-29-2021, 08:30 AM
NewVBAUser NewVBAUser is offline Move all style headings up 1 level Mac OS X Move all style headings up 1 level Office 2016 for Mac
Novice
Move all style headings up 1 level
 
Join Date: Nov 2021
Posts: 3
NewVBAUser is on a distinguished road
Question Move all style headings up 1 level

Hi,



First off apologies, I know next to nothing about VBA. Have been given an output from another program which I need to put into Word to tidy up as a report.

The original programmer has put the title as Heading 1 and then Heading 1 as Heading 2 etc, etc. I don't have the code so can't fix at source.

What I need to do is iterate through the headings and promote them up a level. There is only one Heading 1 so that would become title.
Heading 2 = Heading 1 etc etc.

Have found some code to create a Table Of Contents, but not sure how to set where I want to put it. There is some text before the first Heading 1/title which is always the same so can get rid of, but the Heading will contain varying text so cannot do a standard find.

Want to do all of this in Macros as there will be a lot of these reports to do over the coming months.

Many thanks for any help you can offer.
Reply With Quote
  #2  
Old 11-29-2021, 07:41 PM
Guessed's Avatar
Guessed Guessed is offline Move all style headings up 1 level Windows 10 Move all style headings up 1 level Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,967
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

Select All and then promote. This is done with two keyboard commands
Ctrl-A followed by Alt-Shift-Left Arrow
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 11-30-2021, 04:44 AM
NewVBAUser NewVBAUser is offline Move all style headings up 1 level Mac OS X Move all style headings up 1 level Office 2016 for Mac
Novice
Move all style headings up 1 level
 
Join Date: Nov 2021
Posts: 3
NewVBAUser is on a distinguished road
Default

Thanks for your reply. Unfortunately, that does not work for me on a Mac. I looked out the Outline view and tried to do what you suggested manually and it won't promote a Heading 1 style to a Title style either.

From playing around with things while recording a macro it looks like the following will do what you suggested manually using keyboard shortcuts

Selection.WholeStory
Selection.Paragraphs.OutlinePromote

However I need to somehow automatically select the text of whatever is in style Heading 1 and change that to Title - > Selection.Style = ActiveDocument.Styles("Title")

If anyone knows how I can auto select the Heading 1 text I would be very grateful. The text will be dynamic so I can't look for a set string :-(

Last edited by NewVBAUser; 11-30-2021 at 04:54 AM. Reason: more detail added
Reply With Quote
  #4  
Old 11-30-2021, 02:16 PM
Guessed's Avatar
Guessed Guessed is offline Move all style headings up 1 level Windows 10 Move all style headings up 1 level Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,967
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

Before the outline promote is run you will need to handle the Heading 1 to change its style to Title. This should be done with a Find and Replace. If you are using a macro, this would do it
Code:
Sub Macro2()
  With ActiveDocument.Range.Find
    .ClearFormatting
    .Style = ActiveDocument.Styles("Heading 1")
    .Replacement.ClearFormatting
    .Replacement.Style = ActiveDocument.Styles("Title")
    .Text = ""
    .Wrap = wdFindContinue
    .Format = True
    .Execute Replace:=wdReplaceAll
  End With
  ActiveDocument.Range.Paragraphs.OutlinePromote
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 12-01-2021, 02:48 AM
NewVBAUser NewVBAUser is offline Move all style headings up 1 level Mac OS X Move all style headings up 1 level Office 2016 for Mac
Novice
Move all style headings up 1 level
 
Join Date: Nov 2021
Posts: 3
NewVBAUser is on a distinguished road
Default

Thanks Andrew
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Move all style headings up 1 level Applied Styles to Headings in Multi-Level List; now ALL second level headings are 1.XX NNL Word 1 08-09-2017 02:52 PM
Numbered headings go nuts after level 3/4 billy8b8 Word 11 02-05-2016 08:02 PM
Move all style headings up 1 level Level 2 headings in Word look strange when PDF emmyb Word 1 09-10-2014 11:30 AM
Config style to restart numbering if it it comes after a style of a higher level ghumdinger Word 7 08-31-2011 01:10 AM
Move all style headings up 1 level Headings + Multi-level list falieson Word 1 06-18-2010 12:01 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:02 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