Quote:
Originally Posted by Guessed
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