|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Modifying a Macro that Splits Word Docs by Heading to Skip Some Headings ("Bibliographies")
Hi there! My team and I are looking to edit the Macro from this thread:
https://www.msofficeforums.com/word-...save-file.html Code:
Sub SplitDocByHeading1() Application.ScreenUpdating = False Dim StrTmplt As String, StrPath As String, StrFlNm As String, Rng As Range, i As Long, Doc As Document Const StrNoChr As String = """*./\:?|" With ActiveDocument StrTmplt = .AttachedTemplate.FullName StrPath = .Path & "\" With .Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "" .Replacement.Text = "" .Style = wdStyleHeading1 .Format = True .Forward = True .Wrap = wdFindStop .Execute End With Do While .Find.Found Set Rng = .Duplicate StrFlNm = Split(Rng.Paragraphs(1).Range.Text, vbCr)(0) For i = 1 To Len(StrNoChr) StrFlNm = Replace(StrFlNm, Mid(StrNoChr, i, 1), "_") Next StrFlNm = StrFlNm & ".docx" Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\HeadingLevel") Set Doc = Documents.Add(Template:=StrTmplt, Visible:=False) With Doc .Range.FormattedText = Rng.FormattedText .SaveAs2 FileName:=StrPath & StrFlNm, Fileformat:=wdFormatXMLDocument, AddToRecentFiles:=False .Close False End With .Collapse wdCollapseEnd .Find.Execute Loop End With End With Set Doc = Nothing: Set Rng = Nothing Application.ScreenUpdating = True End Sub This is great for our organization! However, there are times where we want to separate out the bibliography (also a Heading 1) and times where we want to keep it in. We would like to keep two versions of the macro for this reason -- the above and a modified version that keeps in the bibliography. Potential Theoretical Solutions:
Would anyone be able to advise or help me with this task? I am not familiar enough with VBA to know exactly how to parse this out. Thank you! |
Tags |
heading split, macro help, vba |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Excel 2003: VBA "Function" causes "#VALUE!" errors after running "insert/delete row" custom macro | Matt C | Excel Programming | 2 | 01-08-2022 06:03 AM |
Keyboard shortcut to "Show all headings" with the Heading 1 style etc. | Retko | Word | 1 | 12-29-2020 05:41 AM |
Word 2013's Navigation Pane does not show "level 4" headings, even when I click "Show Heading 4" | zrcarlson | Word | 1 | 10-26-2016 09:51 AM |
Navigation Pane: Preselect "results" instead of "headings" | DirkMcCallahan | Word | 1 | 03-24-2016 01:38 PM |
How to choose a "List" for certain "Heading" from "Modify" tool? | Jamal NUMAN | Word | 2 | 07-03-2011 03:11 AM |