excel VBA在邮件合并过程中出现提示时自动选择“是”
我希望这个系统对我的用户来说尽可能自动化。现在,我有了当用户单击按钮时运行的代码。代码获取数据的目的是通过邮件合并将其应用于word文档 一切都按预期进行,只是总有一条信息突然出现 打开此文档将运行以下SQL命令: 从“标记$”中选择* 数据库中的数据将放置在文档中。你想去吗 继续 我需要尽可能地简单,而不让用户因为困惑而选择“否”。VBA如何自动进行并接受数据放置,就像他们选择“是”一样 我试着使用下面的代码来阻止警报,希望它默认为“是”并继续,但它不起作用excel VBA在邮件合并过程中出现提示时自动选择“是”,excel,vba,alert,blocking,mailmerge,Excel,Vba,Alert,Blocking,Mailmerge,我希望这个系统对我的用户来说尽可能自动化。现在,我有了当用户单击按钮时运行的代码。代码获取数据的目的是通过邮件合并将其应用于word文档 一切都按预期进行,只是总有一条信息突然出现 打开此文档将运行以下SQL命令: 从“标记$”中选择* 数据库中的数据将放置在文档中。你想去吗 继续 我需要尽可能地简单,而不让用户因为困惑而选择“否”。VBA如何自动进行并接受数据放置,就像他们选择“是”一样 我试着使用下面的代码来阻止警报,希望它默认为“是”并继续,但它不起作用 Application.Displ
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属性(如果警报来自Word): Word 2013 HKEY\U当前\U用户\软件\ 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.
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.
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.
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 2010
HKEY\U当前\U用户\软件\ 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\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.
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.
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.
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 2007
HKEY\U当前\U用户\软件\ 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\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.
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.
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.
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 2003
HKEY\ U当前\用户\软件\ 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\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.
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.
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.
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\U当前\U用户\软件\ 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\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.
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.
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.
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.
要执行此操作,请执行以下步骤:
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.
您是否也执行Application.ScreenUpdate=False?/有时,在打开的excel手册后面会出现警告消息,我必须手动最小化手册以选择“是”。这并不真正工作,而它被困在执行中等待我选择消息框选项,所以我必须ALT+D,以尽量减少一切,然后选择Excel并单击消息框。你可以想象,这不是很实际。谢谢您的帮助。ScreenUpdate=False不起作用。代码执行得很好,只是没有像我需要的那样通过消息框。尝试在Word中设置DisplayAlerts,而不仅仅是Excel?@Tim Williams-我应该在代码中的何处以及如何实现这一点?我修改了原来的帖子,以显示我目前使用的代码。+1是的,这将与轻微的修改工作
wdAlertsNone
是一个单词常量。将其更改为0
或在顶部声明Const-wdAlertsNone=0
此外,我们在wdDoc
之后不需要应用程序,因为它已经是一个应用程序,所以wdDoc.DisplayAlerts=0
就足够了。@Jean-FrançoisCorbett:是的,但它也有一个相当于0,-1的整数,-2取决于当前设置的内容。(wdAlertsAll-1,wdAlertsMessageBox-2,wdAlertsNone 0
)我从Ashton对其他单词常量的使用中假设他设置了对单词库的引用。这可能是我的一个错误,但在这种情况下,值得指出的是,在使用它们时没有定义它们可能会导致问题。当我在设置wdDoc=GetObject(wdInputName,“Word.document”)之前设置了wdDoc.DisplayAlerts=0时,它显然不起作用,因为没有设置wdDoc。但是如果我把它紧跟在行后面,那就太晚了,因为word才刚刚打开,而这正是消息出现的时间,所以太晚了。您应该先创建word.application的实例,然后使用该实例打开文档。