0
votes

I want to duplicate the text from a word document (everything including headers, footers, tables and textboxes), then I would like to hide the original text (or the hidden one) while keeping the formatting with a macro.

I've do some research and tried to make something, here what I've done until now :

Dim text As Word.Range
Set text = Selection.Range.Duplicate
Selection.InsertParagraphAfter
Selection.InsertAfter Text:=text.Text
text.Font.Hidden = True

The problem with this macro is that doesn't copy the format of the text, its make a copy of the text as a "plain text".

You have an idea of how to keep the formatting?

1
Do you mean headers or headings?Timothy Rylatt
I think headers is the correct translations (en-tête in french)Satanas
Headers and footers are part of the page layout, which cannot be copied easily. Are you copying to the same document?Timothy Rylatt
Thank you for the clarification. Yes, on the same document with the duplicated content next to each other or after the last section/part of the document. To copy this part I think that StoryRanges could help, I'm trying to include it on the code.Satanas

1 Answers

2
votes

The code below should do what you need. You need to ensure that the source range does not include the start of the target range.

Dim source As Range, target As Range
With ActiveDocument
    .Content.InsertParagraphAfter
    Set source = .Content
    source.MoveEnd wdParagraph, -1
    .Characters.Last.FormattedText = source.FormattedText
    source.Font.Hidden = True
End With