View Single Post
 
Old 01-11-2023, 07:39 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,980
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The Paper Size and Header/Footers will only change if there are section breaks included in what you are bringing across. So you can clean the content by deleting section breaks before the transfer to avoid that issue. The Style list reset is repaired by refreshing the styles from the Normal template.

Try this version of the macro
Code:
Sub CopyPasteToTemplate()
  Dim InputDoc As Word.Document, OutputDoc As Word.Document, i As Integer
    
  Set InputDoc = ActiveDocument
  Set OutputDoc = Documents.Add   'Normal template by default
  
  'remove section breaks from input, replace with a hard page break
  With InputDoc.Range.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^b"
    .Replacement.Text = "^m"
    .Wrap = wdFindContinue
    .Execute Replace:=wdReplaceAll
  End With
  
  'make autonumbers and bullets hardcoded
  InputDoc.ConvertNumbersToText (wdNumberAllNumbers)
  
  'Make graphics inline, skip errors
  On Error Resume Next
    For i = InputDoc.Shapes.Count To 1 Step -1
      InputDoc.Shapes(i).ConvertToInlineShape
    Next i
  On Error GoTo 0
  
  'remove formatting from input
  With InputDoc.Range
    .Style = wdStyleNormal
    .ParagraphFormat.Reset
    .Font.Reset
    OutputDoc.Range.FormattedText = .FormattedText      'bring content into new doc
  End With
  
  OutputDoc.UpdateStyles    'restore style settings in output from Normal template
  OutputDoc.Activate
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia

Last edited by Guessed; 01-12-2023 at 06:54 PM. Reason: Edited code to deal with subsequent request
Reply With Quote