View Single Post
 
Old 02-09-2022, 08:06 AM
Axis Axis is offline Windows 11 Office 2019
Novice
 
Join Date: Feb 2022
Posts: 5
Axis is on a distinguished road
Default

Awesome, I appreciate it...especially coming from you!

I did run into an issue where some of the smaller docs of 2 or 3 pages didn't have any sections at all, so I though to run a macro that goes through all of the documents and puts section breaks at the end of every page. It shouldn't do any harm if they already have section breaks should it? I will say when running this section break macro, I sometimes run into "object refers to a framed paragraph" error that kills the run and I have to manually edit that document.

Code:
Sub InsertBreaksIntoMultiDoc()
  Dim StrFolder As String
  Dim strFile As String
  Dim objDoc As Document
  Dim dlgFile As FileDialog
  Dim nTotalPageNumber As Integer
 
  Set dlgFile = Application.FileDialog(msoFileDialogFolderPicker)
 
  With dlgFile
    If .Show = -1 Then
      StrFolder = .SelectedItems(1) & "\"
    Else
      MsgBox "No folder is selected! Please select the target folder."
      Exit Sub
    End If
  End With
 
  strFile = Dir(StrFolder & "*.docx", vbNormal)
 
  While strFile <> ""
    Set objDoc = Documents.Open(FileName:=StrFolder & strFile)
    For nTotalPageNumber = 1 To Selection.Information(wdNumberOfPagesInDocument)
      Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=nTotalPageNumber
      Application.Browser.Target = wdBrowsePage
      ActiveDocument.Bookmarks("\page").Range.Select
      Selection.Collapse wdCollapseEnd
      Selection.InsertBreak Type:=wdSectionBreakContinuous
    Next
    objDoc.Save
    objDoc.Close
    strFile = Dir()
  Wend
End Sub
Reply With Quote