View Single Post
 
Old 03-12-2024, 11:48 AM
Trio78 Trio78 is offline Windows 11 Office 2021
Novice
 
Join Date: Mar 2024
Posts: 3
Trio78 is on a distinguished road
Default Copy Current Section to a New Document

I have a document that is separated by section breaks. I want to have a macro that will take the current section (where my cursor is) and copy it into a new document.

I'm getting the Run-time error '4605' (This command is not available), which my web research suggests is due to using the .Copy and .PasteAndFormat functions. What I haven't been able to figure out is how to rewrite this without using those functions, however!

Code:
Sub CopyCurrentSectionToNewDoc()
  currentSection = Selection.Information(wdActiveEndSectionNumber)
  With ActiveDocument.Sections(currentSection)
    Set Rng = .Range
      With Rng
        .MoveEnd wdCharacter, -1
        .Copy
      End With
  End With
  
  Set NewDoc = Documents.Add(Template:=ActiveDocument.AttachedTemplate.FullName, Visible:=True)
    
  With NewDoc
    ' Paste contents into the output document, preserving the formatting
    .Range.PasteAndFormat (wdFormatOriginalFormatting)
  End With

End Sub
Reply With Quote