tags:

views:

335

answers:

1

I have some VSTO code which generates a Word 2003 document by copying and pasting selected sections from a source document:

    Dim doc = Globals.ThisDocument.Application.Documents.Add(DocumentType:=Word.WdNewDocumentType.wdNewBlankDocument, Visible:=False)
    For Each sectionNumber As Integer In requiredSections
        sourceDoc.Sections(sectionNumber).Range.Copy()
        doc.Bookmarks("\endofdoc").Range.Paste()
    Next
    doc.SaveAs(FileName:=(fileName), FileFormat:=(format), LockComments:=False, Password:="", AddToRecentFiles:=False)
    doc.Close(SaveChanges:=False)

This works fine, but when I open the resulting document, I get the macros security warning dialog box (or the doc opens in design mode, depending on settings). I can't see any macros in the document at all, e.g. with the Macro Organizer in Word.

The real problem that this is causing is that it prevents printing from the shell from working if macro security is set to "High" (the code is invoking Process.Start on the document with the Print verb specified, which is the preferred print mechanism as it works for many document types).

The weird thing is that the problem only occurs if more than one section is pasted to the target document.

Anyone have any ideas? Thanks.

A: 

Two hours, and no-one's done my work for me ;-)

Just in case anyone else has this problem, I eventually worked around it by saving the document as RTF so there are no macros and the shell print works without a hitch.

Now I wait with bated breath for someone to report limitations in the Word RTF output.

Ian Horwill