Preservation of Macros

GemBox.Document supports most Microsoft Word features, but not all. You can preserve unsupported features when reading a document so that they are not lost when writing to a document of the same format.

You can read more about GemBox.Document's preservation feature on the Preservation help page.

The following example shows how you can preserve macros in a Word document from input to output.

Reading and writing Word document with preserved macros
Screenshot of Word file with preserved macros
Upload your file (Drag file here)
using GemBox.Document;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        // Load Word document with preservation feature enabled.
        var loadOptions = new DocxLoadOptions() { PreserveUnsupportedFeatures = true };
        var document = DocumentModel.Load("%InputFileName%", loadOptions);

        // Save Word document to output file of same format together with
        // preserved information (unsupported features) from input file.
        document.Save("Preserved Output.docm");
    }
}
Imports GemBox.Document

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        ' Load Word document with preservation feature enabled.
        Dim loadOptions As New DocxLoadOptions() With {.PreserveUnsupportedFeatures = True}
        Dim document = DocumentModel.Load("%InputFileName%", loadOptions)

        ' Save Word document to output file of same format together with
        ' preserved information (unsupported features) from input file.
        document.Save("Preserved Output.docm")

    End Sub
End Module

See also


Next steps

GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API. How about testing it today?

Download Buy