View Single Post
 
Old 08-09-2021, 01:11 AM
RobertDany RobertDany is offline Windows 7 64bit Office 2013
Novice
 
Join Date: Jul 2021
Posts: 22
RobertDany is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
Do you need this in Word or would a PDF output work for you? Printing a range to PDF will give you an exact extract.
Dear Andrew, thank you for your comment
I prefer in word doc, because many VBA codes are available online for this purpose.

Currently, I use this code to copy selected range to a new doc, but it just copy selected without header and footer

Code:
Sub CopySelectedRangeToNewDoc()
'UpdatebyExtendoffice20181115

Dim Path As String
Path = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\"

    Selection.Copy
    Documents.Add , , wdNewBlankDocument
    Selection.Paste
End Sub
Also, I use this code to copy selected range to pdf, but also without header and footer

Code:
Sub SaveSelectionAsPDF()
'UpdatebyExtendoffice20181115

    Dim xFolder As Variant
    Dim xDlg As FileDialog
    Dim xFileName As String
    Set xDlg = Application.FileDialog(msoFileDialogFolderPicker)
    If xDlg.Show <> -1 Then Exit Sub
    xFolder = xDlg.SelectedItems(1)
    xFileName = InputBox("Enter file name here:", "KuTools for Word")
    Selection.ExportAsFixedFormat xFolder & "\" & xFileName, wdExportFormatPDF, _
                True, wdExportOptimizeForPrint, False, wdExportDocumentContent, True, True, wdExportCreateNoBookmarks, _
                True, True, False
End Sub
Additionally, this code export the selected range of pages in pdf format with header and footer, but you need to insert the range manually each run of the code which may be annoying


Code:
Sub SavePageRangeAsPDF()

    ActiveDocument.ExportAsFixedFormat _
     OutputFileName:=CurrentFolder & "Robert" & ".pdf", _
     ExportFormat:=wdExportFormatPDF, _
range:=wdExportFromTo, From:=2, To:=4

End Sub

hence, I want to export it in word doc, as Mr. Paul split the document by heading with header and footer.

Thank you
Reply With Quote