尝试使用VB.NET控制台应用程序打印MS Word文档,但是通过宏对话框停止

时间:2016-10-17 16:29:46

标签: vb.net ms-word

我正在尝试打印MS Word文档,但是对于包含宏的文档,我会被警告消息停止"此项目中的宏被禁用。"

我已经尝试使用DisabledAutoMacros和AutomationSecurity禁用此消息。

有没有办法避免这个对话框,或者感觉它并点击确定,或设置超时来杀死进程如果我无法通过它?

Imports word = Microsoft.Office.Interop.Word
Module Module1
    Sub Main()
        Dim args() As String = Environment.GetCommandLineArgs
        Dim path = args(1)
        Dim printer = args(2)
        Dim wordApp As word.Application = New word.Application
        wordApp.WordBasic.DisableAutoMacros(1)
        wordApp.AutomationSecurity = 3
        wordApp.Visible = False
        Dim doc As word.Document = wordApp.Documents.Open(path)
        wordApp.ActivePrinter = printer
        Dim background As Object = False
        doc.PrintOut(background)
        doc.Close(False)
        wordApp.WordBasic.DisableAutoMacros(0)
        wordApp.Quit()
    End Sub
End Module

enter image description here

0 个答案:

没有答案