excel VBA 在邮件合并期间出现提示时自动选择是
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11301716/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
excel VBA to Automatically select Yes when prompted during mail merge
提问by Ashton Sheets
I'd like the system to be as automated for my users as possible. Right now, I have code that runs when the user clicks a button. The code takes data with the intention of applying it to a word document via mail merge.
我希望系统尽可能为我的用户自动化。现在,我有当用户单击按钮时运行的代码。该代码获取数据的目的是通过邮件合并将其应用于 Word 文档。
Everything works as intended except there's always a message that pops up saying
一切都按预期工作,除了总是弹出一条消息说
Opening this document will run the following SQL command:
Select * FROM 'TAGS$'
Data from your database will be placed in the document. Do you want to continue?
打开此文档将运行以下 SQL 命令:
从“标签$”中选择*
数据库中的数据将放置在文档中。你要继续吗?
I need to keep this as simple as possible without risking users selecting "No" because they're confused. How can VBA automatically proceed and accept the data placement, as it would had they selected "Yes"?
我需要使这尽可能简单,而不会让用户因为感到困惑而选择“否”。VBA 如何自动进行并接受数据放置,就像他们选择“是”一样?
I tried just using the following code to block alerts in hopes it would default "Yes" and proceed, but it didn't work.
我尝试只使用以下代码来阻止警报,希望它默认为“是”并继续,但它没有用。
Application.DisplayAlerts = False
This is what I have
这就是我所拥有的
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
回答by Tim Williams
Try setting the DisplayAlerts property in Word (if that's where the alert is coming from):
尝试在 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
回答by Vladislav Rastrusny
http://support.microsoft.com/kb/825765
http://support.microsoft.com/kb/825765
Word 2013
词 2013
HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Word\Options
HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Word\Options
"SQLSecurityCheck"=dword:00000000
"SQLSecurityCheck"=dword:00000000
Start Registry Editor.
Locate and then click the following registry key:
HKEY_CURRENT_USER\Software\Microsoft\Office.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
词 2010
HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Word\Options
HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Word\Options
"SQLSecurityCheck"=dword:00000000
"SQLSecurityCheck"=dword:00000000
Start Registry Editor.
Locate and then click the following registry key:
HKEY_CURRENT_USER\Software\Microsoft\Office.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
词 2007
HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Word\Options
HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Word\Options
"SQLSecurityCheck"=dword:00000000
"SQLSecurityCheck"=dword:00000000
Start Registry Editor.
Locate and then click the following registry key:
HKEY_CURRENT_USER\Software\Microsoft\Office.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
字 2003
HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Word\Options
HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Word\Options
"SQLSecurityCheck"=dword:00000000
"SQLSecurityCheck"=dword:00000000
Start Registry Editor.
Locate and then click the following registry key:
HKEY_CURRENT_USER\Software\Microsoft\Office.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
Word 2002 服务包 3
HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Word\Options
HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Word\Options
"SQLSecurityCheck"=dword:00000000
"SQLSecurityCheck"=dword:00000000
To do this, follow these steps:
为此,请按照下列步骤操作:
Start Registry Editor.
Locate and then click the following registry key:
HKEY_CURRENT_USER\Software\Microsoft\Office.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.