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.