Skip to content

Instantly share code, notes, and snippets.

@brrd
Last active February 6, 2016 12:50
Show Gist options
  • Save brrd/15942342834877596f91 to your computer and use it in GitHub Desktop.
Save brrd/15942342834877596f91 to your computer and use it in GitHub Desktop.
Word: BreakOnSection
'Inspiration: https://support.microsoft.com/fr-fr/kb/306348
Sub BreakOnSection()
'Move cursor to first line
Selection.GoTo What:=wdGoToHeading, Which:=wdGoToFirst
' Used to set criteria for moving through the document by section.
Application.Browser.Target = wdBrowseSection
'S'il y a un saut de section à la fin du doc
For i = 1 To ((ActiveDocument.Sections.Count) - 1)
' Si pas de saut de section à la fin
'For i = 1 To ActiveDocument.Sections.Count
'Select and copy the section text to the clipboard.
ActiveDocument.Bookmarks("\Section").Range.Copy
'Create a new document to paste text from clipboard.
Documents.Add
Selection.Paste
ChangeFileOpenDirectory "C:\Documents\Path\to\docs"
DocNum = DocNum + 1
'Sauver en DOC
ActiveDocument.SaveAs FileName:="doc" & DocNum & ".doc"
'...ou en HTM
'ActiveDocument.SaveAs FileName:="doc" & DocNum & ".htm", FileFormat:=wdFormatHTML
ActiveDocument.Close
' Move the selection to the next section in the document.
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub
@brrd
Copy link
Author

brrd commented Feb 6, 2016

  1. Remplacer tous les sauts de sections du document source par des sauts de paragraphe.
    Rechercher : ^b
    Remplacer par : ^p
  2. Replacer les sauts de section dans le document aux endroit ou on doit splitter. Il faut faire gaffe à ajouter un saut de section à la fin du dernier article (voir code de la macro).
  3. Choisir dans la macro le chemin de sortie et le format destination (HTM ou DOC) en modifiant le code source.
  4. Lancer la macro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment