Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-02-2022, 04:12 PM
macropod's Avatar
macropod macropod is offline VBA to separate doc and docm format Windows 10 VBA to separate doc and docm format Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,521
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

For example:


Code:
Sub SplitByHeading1()
Application.ScreenUpdating = False
Dim RngHd As Range, i As Long, Doc As Document, StrNm As String, StrExt As String, Fmt As Long
With ActiveDocument
  Fmt = .SaveFormat
  StrNm = Split(.FullName, ".do")(0)
  StrExt = ".do" & Split(.FullName, ".do")(1)
  With .Range
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = ""
      .Style = wdStyleHeading1
      .Replacement.Text = ""
      .Forward = True
      .Wrap = wdFindStop
      .Format = True
    End With
    Do While .Find.Execute
      Set RngHd = .Paragraphs(1).Range.GoTo(What:=wdGoToBookmark, Name:="\HeadingLevel")
      Set Doc = Documents.Add(ActiveDocument.AttachedTemplate.FullName): i = i + 1
      With Doc
        .Range.FormattedText = RngHd.FormattedText
        .SaveAs2 FileName:=StrNm & "(" & i & ")" & StrExt, Fileformat:=Fmt, AddToRecentFiles:=False
        .Close False
      End With
      .Start = RngHd.End
    Loop
  End With
End With
Set RngHd = Nothing: Set Doc = Nothing
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Split Table in separate rows and turn in picture Format allenku Word VBA 1 08-08-2021 08:29 PM
VBA to separate doc and docm format Format tab leader in “Table of figures” separate from text? WTR_girl12 Word 1 09-03-2015 10:48 AM
How do I separate an address into separate cells Austcart Excel 2 01-18-2015 03:48 PM
VBA to separate doc and docm format Can I use the filter function to separate letters into separate files? drhauser Mail Merge 2 12-14-2011 02:18 PM
Any easy way to separate a Word document into separate files? SamHelm Word 0 08-21-2010 05:29 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:43 PM.


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