Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-03-2025, 03:07 PM
stusic stusic is offline VBA to Copy Text Between Heading Styles to New File Windows 10 VBA to Copy Text Between Heading Styles to New File Office 2021
Novice
VBA to Copy Text Between Heading Styles to New File
 
Join Date: Jan 2025
Posts: 4
stusic is on a distinguished road
Question VBA to Copy Text Between Heading Styles to New File

Hello All!




I've got a lengthy document and I need to create individual documents for each of the headings I have to a new file.


It's laid out like this:
Code:
FirstTitleInHeading3Style

FirstTopicTextInNormalStyle 



SecondTitleInHeading3Style

SecondTopicTextInNormalStyle
From the following example, one file (FirstTitleInHeading3Style.doc) would be:


Code:
FirstTitleInHeading3Style

FirstTopicTextInNormalStyle
And the next file (SecondTitleInHeading3Style.doc) would be:


Code:
SecondTitleInHeading3Style

SecondTopicTextInNormalStyle
I know there's a way to separate it by isolating the text between the styles (Header 3), but I'm not sure how to go about it.


Any help would be greatly appreciated.


Thanks!


-stu

Last edited by stusic; 01-03-2025 at 03:09 PM. Reason: typo
Reply With Quote
  #2  
Old 01-03-2025, 03:35 PM
macropod's Avatar
macropod macropod is offline VBA to Copy Text Between Heading Styles to New File Windows 10 VBA to Copy Text Between Heading Styles to New File Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,385
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

See: https://www.msofficeforums.com/word-...save-file.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-06-2025, 07:40 AM
stusic stusic is offline VBA to Copy Text Between Heading Styles to New File Windows 10 VBA to Copy Text Between Heading Styles to New File Office 2021
Novice
VBA to Copy Text Between Heading Styles to New File
 
Join Date: Jan 2025
Posts: 4
stusic is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post

That's perfect! I don't know how I didn't find that in my search, but thanks again!
Reply With Quote
  #4  
Old 01-06-2025, 08:00 AM
stusic stusic is offline VBA to Copy Text Between Heading Styles to New File Windows 10 VBA to Copy Text Between Heading Styles to New File Office 2021
Novice
VBA to Copy Text Between Heading Styles to New File
 
Join Date: Jan 2025
Posts: 4
stusic is on a distinguished road
Default

One question I ran into, but didn't want to resurrect a dead thread: What if I don't have any bookmarks in my doc? I get an error when I get to this:

Code:
Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\HeadingLeve3")
As a guess, I tried this (but didn't work either, surprised /s)
Code:
Set Rng = Rng.GoTo(What:=wdGoHeading, Name:="\HeadingLeve3")
Reply With Quote
  #5  
Old 01-06-2025, 08:26 AM
Italophile Italophile is offline VBA to Copy Text Between Heading Styles to New File Windows 11 VBA to Copy Text Between Heading Styles to New File Office 2021
Expert
 
Join Date: Mar 2022
Posts: 542
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Quote:
Originally Posted by stusic View Post
One question I ran into, but didn't want to resurrect a dead thread: What if I don't have any bookmarks in my doc? I get an error when I get to this:

Code:
Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\HeadingLeve3")
As a guess, I tried this (but didn't work either, surprised /s)
Code:
Set Rng = Rng.GoTo(What:=wdGoHeading, Name:="\HeadingLeve3")
Your code is incorrect. The code linked to by macropod is:

Code:
Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\HeadingLevel")
You can learn more about predefined bookmarks in Word at Predefined Bookmarks | Microsoft Learn
Reply With Quote
  #6  
Old 01-06-2025, 10:15 AM
stusic stusic is offline VBA to Copy Text Between Heading Styles to New File Windows 10 VBA to Copy Text Between Heading Styles to New File Office 2021
Novice
VBA to Copy Text Between Heading Styles to New File
 
Join Date: Jan 2025
Posts: 4
stusic is on a distinguished road
Default

Quote:
Originally Posted by Italophile View Post
Your code is incorrect. The code linked to by macropod is:

Code:
Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\HeadingLevel")
You can learn more about predefined bookmarks in Word at Predefined Bookmarks | Microsoft Learn

Oh wow, a typo. I read it as "HeadingLevel1" and still messed it up, lol. Thanks, I appreciate it.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Stop styles from being copy pasted along with text Word_fail Word 4 07-10-2017 05:50 AM
Style for Text Changes from Normal to Heading 1 when Copy-Pasted Basia Word 8 08-15-2015 02:32 PM
VBA to Copy Text Between Heading Styles to New File Heading styles with text formatting othromas Word 9 11-13-2013 03:10 PM
VBA to Copy Text Between Heading Styles to New File Styles: Heading 4 stuck at same heading number Hallet Word 1 05-31-2012 02:37 PM
Copy + Paste from Word to Word WITHOUT heading styles altjx Word 4 04-18-2012 12:36 AM

Other Forums: Access Forums

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