View Single Post
 
Old 01-22-2024, 08:59 AM
tonykekw tonykekw is offline Windows 11 Office 2021
Novice
 
Join Date: Jan 2024
Posts: 13
tonykekw is on a distinguished road
Default

youre right, we don't know. Thats something I will have to go in and re-structure the document for. Disregarding the sentence or paragraph. Only the section headers would work for now.

I wrote a script but it just copy pasted the entire docuemnt twice. Or I recive a runtime error.

Code:
Sub OrganizeSections()
    Dim doc As Document
    Dim sec As Section
    Dim newSection As Section
    
    ' Set the source document
    Set doc = ActiveDocument
    
    ' Disable screen updating to improve performance
    Application.ScreenUpdating = False
    
    ' Loop through each section in the source document
    For Each sec In doc.Sections
        ' Check if the section contains "[A]"
        If InStr(sec.Range.Text, "[A]") > 0 Then
            ' Create a new section after the current one
            Set newSection = doc.Sections.Add
            ' Copy the content of the section to the new section
            newSection.Range.FormattedText = sec.Range.FormattedText
            ' Add a new line after the copied section
            newSection.Range.InsertAfter vbNewLine
        End If
    Next sec
    
    ' Enable screen updating
    Application.ScreenUpdating = True
End Sub
Reply With Quote