Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-02-2022, 11:08 AM
jtm4890 jtm4890 is offline VBA to separate doc and docm format Windows 10 VBA to separate doc and docm format Office 2021
Novice
VBA to separate doc and docm format
 
Join Date: Oct 2022
Posts: 2
jtm4890 is on a distinguished road
Default VBA to separate doc and docm format

1 Anyone knows how to use VBA to separate a doc in multiple xdoc separated docs per each Heading 1 (like break page format).


2 And where is the format similar to xlam (excel app) format for MS Word, I did not find any method to create VBA app like excel. If there is not a like xlam format for MS Word, what is the alternative to create apps.
Reply With Quote
  #2  
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: 21,963
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 07:15 AM.


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