Last active
February 6, 2016 12:50
-
-
Save brrd/15942342834877596f91 to your computer and use it in GitHub Desktop.
Word: BreakOnSection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rechercher : ^b
Remplacer par : ^p