#1
|
|||
|
|||
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. |
#2
|
||||
|
||||
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] |
|
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 |
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 |
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 |