Excel VBA在邮件合并期间提示时自动选​​择是

我希望系统尽可能为用户自动执行。 现在,我有用户单击button时运行的代码。 该代码将数据打算通过邮件合并应用于Word文档。

一切都按预期工作,除了总是有一条消息popup来说

打开这个文档将运行下面的SQL命令:

select* FROM'TAGS $'

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

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

我试着用下面的代码来阻止警报,希望它默认“是”并继续,但没有奏效。

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 

尝试在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 

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

Word 2013

HKEY_CURRENT_USER \软件\微软\办公室\ 15.0 \ Word中\选项

“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. 

Word 2010

HKEY_CURRENT_USER \软件\微软\办公室\ 14.0 \ Word中\选项

“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. 

Word 2007

HKEY_CURRENT_USER \软件\微软\办公室\ 12.0 \ Word中\选项

“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. 

Word 2003

HKEY_CURRENT_USER \软件\微软\办公室\ 11.0 \ Word中\选项

“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 Service Pack 3

HKEY_CURRENT_USER \软件\微软\办公室\ 10.0 \ Word中\选项

“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.