Import/Export related procedures in class Range (Word VBA)

This page presents procedures from class Range related to the theme Import/Export: ExportAsFixedFormat, ExportAsFixedFormat2, ExportFragment and ImportFragment

ExportAsFixedFormat

Saves a portion of a document as PDF or XPS format.

You can save as a PDF or XPS file from a Microsoft Office system program only after you install an add-in. For more information, see Save or convert to PDF or XPS.

Syntax : expression.ExportAsFixedFormat (OutputFileName, ExportFormat, OpenAfterExport, OptimizeFor, ExportCurrentPage, Item, IncludeDocProps, KeepIRM, CreateBookmarks, DocStructureTags, BitmapMissingFonts, UseISO19005_1, FixedFormatExtClassPtr)

Dim strOutputFileName As String: strOutputFileName =  
ActiveDocument.Range.ExportAsFixedFormat OutputFileName:=strOutputFileName, ExportFormat:=wdExportFormatPDF

Arguments

The following arguments are required:

OutputFileName (String) - The path and file name of the new PDF or XPS file.

ExportFormat (WdExportFormat) - Specifies either PDF or XPS format.

Possible Values are wdExportFormatPDF - Export document into PDF format, wdExportFormatXPS - Export document into XML Paper Specification (XPS) format.

The following arguments are optional

OpenAfterExport (Boolean) - Opens the new file after exporting the contents.

OptimizeFor (WdExportOptimizeFor) - Specifies whether to optimize for screen or print.

Possible Values are wdExportOptimizeForOnScreen - Export for screen, which is a lower quality and results in a smaller file size, wdExportOptimizeForPrint - Export for print, which is higher quality and results in a larger file size.

ExportCurrentPage (Boolean) - Specifies whether to export the current page. True exports the entire page. False exports only the current selection.

Item (WdExportItem) - Specifies whether the export process includes text only or includes text with markup.

Possible Values are wdExportDocumentContent - Exports the document without markup, wdExportDocumentWithMarkup - Exports the document with markup.

IncludeDocProps (Boolean) - Specifies whether to include document properties in the newly exported file.

KeepIRM (Boolean) - Specifies whether to copy IRM permissions to an XPS document if the source document has IRM protections. Default value is True.

CreateBookmarks (WdExportCreateBookmarks) - Specifies whether to export bookmarks and the type of bookmarks to export.

Possible Values are wdExportCreateHeadingBookmarks - Create a bookmark in the exported document for each Microsoft Word heading, which includes only headings within the main document and text boxes not within headers, footers, endnotes, footnotes, or comments, wdExportCreateNoBookmarks - Do not create bookmarks in the exported document, wdExportCreateWordBookmarks - Create a bookmark in the exported document for each Word bookmark, which includes all bookmarks except those contained within headers and footers.

DocStructureTags (Boolean) - Specifies whether to include extra data to help screen readers, for example information about the flow and logical organization of the content. Default value is True.

BitmapMissingFonts (Boolean) - Specifies whether to include a bitmap of the text. Set this parameter to True when font licenses do not permit a font to be embedded in the PDF file. If False, the font is referenced, and the viewer's computer substitutes an appropriate font if the authored one is not available. Default value is True.

UseISO19005_1 (Boolean) - Specifies whether to limit PDF usage to the PDF subset standardized as ISO 19005-1. If True, the resulting files are more reliably self-contained but may be larger or show more visual artifacts due to the restrictions of the format. Default value is False.

FixedFormatExtClassPtr - Specifies a pointer to an add-in that allows calls to an alternate implementation of code. The alternate implementation of code interprets the EMF and EMF+ page descriptions that are generated by the applications to make their own PDF or XPS. For more information, see Extend the fixed-format export feature in Word Automation Services

ExportAsFixedFormat2

Saves a portion of a document as PDF or XPS format.

You can save as a PDF or XPS file from a Microsoft Office system program only after you install an add-in. For more information, see Save or convert to PDF or XPS.

Syntax : expression.ExportAsFixedFormat2 (OutputFileName, ExportFormat, OpenAfterExport, OptimizeFor, ExportCurrentPage, Item, IncludeDocProps, KeepIRM, CreateBookmarks, DocStructureTags, BitmapMissingFonts, UseISO19005_1, OptimizeForImageQuality, FixedFormatExtClassPtr)

Dim strOutputFileName As String: strOutputFileName =  
ActiveDocument.Range.ExportAsFixedFormat2 OutputFileName:=strOutputFileName, ExportFormat:=wdExportFormatPDF

Arguments

The following arguments are required:

OutputFileName (String) - The path and file name of the new PDF or XPS file.

ExportFormat (WdExportFormat) - Specifies either PDF or XPS format.

Possible Values are wdExportFormatPDF - Export document into PDF format, wdExportFormatXPS - Export document into XML Paper Specification (XPS) format.

The following arguments are optional

OpenAfterExport (Boolean) - Opens the new file after exporting the contents.

OptimizeFor (WdExportOptimizeFor) - Specifies whether to optimize for screen or print.

Possible Values are wdExportOptimizeForOnScreen - Export for screen, which is a lower quality and results in a smaller file size, wdExportOptimizeForPrint - Export for print, which is higher quality and results in a larger file size.

ExportCurrentPage (Boolean) - Specifies whether to export the current page. True exports the entire page. False exports only the current selection.

Item (WdExportItem) - Specifies whether the export process includes text only or includes text with markup.

Possible Values are wdExportDocumentContent - Exports the document without markup, wdExportDocumentWithMarkup - Exports the document with markup.

IncludeDocProps (Boolean) - Specifies whether to include document properties in the newly exported file.

KeepIRM (Boolean) - Specifies whether to copy IRM permissions to an XPS document if the source document has IRM protections. Default value is True.

CreateBookmarks (WdExportCreateBookmarks) - Specifies whether to export bookmarks and the type of bookmarks to export.

Possible Values are wdExportCreateHeadingBookmarks - Create a bookmark in the exported document for each Microsoft Word heading, which includes only headings within the main document and text boxes not within headers, footers, endnotes, footnotes, or comments, wdExportCreateNoBookmarks - Do not create bookmarks in the exported document, wdExportCreateWordBookmarks - Create a bookmark in the exported document for each Word bookmark, which includes all bookmarks except those contained within headers and footers.

DocStructureTags (Boolean) - Specifies whether to include extra data to help screen readers, for example information about the flow and logical organization of the content. Default value is True.

BitmapMissingFonts (Boolean) - Specifies whether to include a bitmap of the text. Set this parameter to True when font licenses do not permit a font to be embedded in the PDF file. If False, the font is referenced, and the viewer's computer substitutes an appropriate font if the authored one is not available. Default value is True.

UseISO19005_1 (Boolean) - Specifies whether to limit PDF usage to the PDF subset standardized as ISO 19005-1. If True, the resulting files are more reliably self-contained but may be larger or show more visual artifacts due to the restrictions of the format. Default value is False.

OptimizeForImageQuality (Boolean) - Specifies whether to downsample images or keep their original quality. If True, the resulting files will have better image quality but may be larger. Default value is False.

FixedFormatExtClassPtr - Specifies a pointer to an add-in that allows calls to an alternate implementation of code. The alternate implementation of code interprets the EMF and EMF+ page descriptions that are generated by the applications to make their own PDF or XPS. For more information, see Extend the fixed-format export feature in Word Automation Services

ExportFragment

Exports the selected range into a document for use as a document fragment.

Syntax : expression.ExportFragment (FileName, Format)

Dim strFileName As String: strFileName =  
ActiveDocument.Range.ExportFragment FileName:=strFileName, Format:=wdFormatDocument

Arguments

The following arguments are required:

FileName (String) - Specifies the path and file name of the file in which to save the document fragment.

Format (WdSaveFormat) - Specifies the file format of the document fragment file.

Here you can find possible values for WdSaveFormat.

ImportFragment

Imports a document fragment into the document at the specified range.

This method replaces the contents of a range. To stop this from occurring, use the Collapse method before using this method.

Syntax : expression.ImportFragment (FileName, MatchDestination)

Dim strFileName As String: strFileName =  
ActiveDocument.Range.ImportFragment FileName:=strFileName

Arguments

The following argument is required

FileName (String) - Specifies the path and file name where the document fragment is stored.

The following argument is optional

MatchDestination (Boolean) - Specifies whether to match the destination formatting. If False, the imported document fragment retains the formatting in the original document. Default value is False.