3

我希望系统对我的用户尽可能自动化。现在,我有在用户单击按钮时运行的代码。该代码获取数据的目的是通过邮件合并将其应用于 Word 文档。

一切都按预期工作,除了总是弹出一条消息说

打开此文档将运行以下 SQL 命令:

选择 * FROM 'TAGS$'

数据库中的数据将被放置在文档中。你想继续吗?

我需要尽可能简单地保持这一点,而不会冒着用户选择“否”的风险,因为他们感到困惑。VBA 如何自动继续并接受数据放置,就像他们选择“是”一样?

我尝试仅使用以下代码来阻止警报,希望它会默认为“是”并继续,但它不起作用。

Application.DisplayAlerts = False

这就是我所拥有的

Sub RunMailMerge()

    Application.ScreenUpdating = False

    Dim wdOutputName, wdInputName As String
    wdOutputName = ThisWorkbook.Path & "\nametags - " _
        & Format(Date, "d mmm yyyy")
    wdInputName = ThisWorkbook.Path & "\nametags.docx"

    ' open the mail merge layout file
    Dim wdDoc As Object
    Set wdDoc = GetObject(wdInputName, "Word.document")
    wdDoc.Application.Visible = True

    With wdDoc.MailMerge
         .MainDocumentType = wdFormLetters
         .Destination = wdSendToNewDocument
         .SuppressBlankLines = True
         .Execute Pause:=False
    End With

    'Application.ScreenUpdating = True

    'show and save output file
    wdDoc.Application.Visible = True
    wdDoc.Application.ActiveDocument.SaveAs wdOutputName

    ' cleanup
    wdDoc.Close SaveChanges:=False
    'activedoc.Close
    Set wdDoc = Nothing

End Sub
4

2 回答 2

2

尝试在 Word 中设置 DisplayAlerts 属性(如果这是警报的来源):

Dim tmp as Long

tmp = wdDoc.Application.DisplayAlerts 

wdDoc.Application.DisplayAlerts = wdAlertsNone
'do the action which causes the prompt
wdDoc.Application.DisplayAlerts = tmp
于 2012-07-02T23:19:07.630 回答
2

http://support.microsoft.com/kb/825765

词 2013

HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Word\Options

"SQLSecurityCheck"=dword:00000000

Start Registry Editor.
Locate and then click the following registry key:

HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Word\Options
On the Edit menu, point to New, and then click DWORD Value.
Under Name, type:

SQLSecurityCheck
Double-click SQLSecurityCheck.
In the Value data box, type:

00000000
Click OK.

词 2010

HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Word\Options

"SQLSecurityCheck"=dword:00000000

Start Registry Editor.
Locate and then click the following registry key:
HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Word\Options
On the Edit menu, point to New, and then click DWORD Value.
Under Name, type:
SQLSecurityCheck
Double-click SQLSecurityCheck.
In the Value data box, type:
00000000
Click OK.

词 2007

HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Word\Options

"SQLSecurityCheck"=dword:00000000

Start Registry Editor.
Locate and then click the following registry key:
HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Word\Options
On the Edit menu, point to New, and then click DWORD Value.
Under Name, type:
SQLSecurityCheck
Double-click SQLSecurityCheck.
In the Value data box, type:
00000000
Click OK.

词 2003

HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Word\Options

"SQLSecurityCheck"=dword:00000000

Start Registry Editor.
Locate and then click the following registry key:
HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Word\Options
Click Edit, point to New, and then click DWORD Value.
Under Name, type:
SQLSecurityCheck
Double-click SQLSecurityCheck.
In the Value data box, type:
00000000
Click OK.

Word 2002 服务包 3

HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Word\Options

"SQLSecurityCheck"=dword:00000000

为此,请按照下列步骤操作:

Start Registry Editor.
Locate and then click the following registry key:
HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Word\Options
Click Edit, point to New, and then click DWORD Value.
Under Name, type:
SQLSecurityCheck
Double-click SQLSecurityCheck.
In the Value data box, type:
00000000
Click OK.
于 2014-04-08T16:04:56.790 回答