如何使用VBA对任何SQL提示说'Yes'?

How to use VBA to say 'Yes' to any SQL prompts in word?

我正在使用从 word 文档启动的宏,它可以打开、执行和关闭一系列其他文档,每个文档都包含一个执行邮件合并的宏。代码运行良好,但每次打开新文档时,都会出现 SQL 提示,询问我是否要将数据从数据源放入我的文档中。

我只能对所有这些对话框说 'Yes',但是

使用以下线程,我设法将代码放入其中,为所有消息框选择 'default' 选项,但它不起作用,因为对我来说,SQL 的默认选项提示是 'No'.

excel VBA to Automatically select Yes when prompted during mail merge

(我知道您也可以通过进入注册表来禁用提示,但这对我来说不是一个选项,因为我需要它在许多计算机上工作,而且我无法在所有计算机上编辑注册表各种原因)。

这是目前的代码(已编辑文件路径):

Sub castingbookmaster()
    '
    ' castingbookmaster Macro
    '
    '
        Dim tmp as Long
        tmp = Documents.Application.Displayalerts
        Documents.Application.Displayalerts = 0
        ChangeFileOpenDirectory "Y:\zzz\"
        Documents.Open FileName:= _
            "Y:\zzz\Mail Merge - All Active Scripts, Alphabetical.docm" _
            , ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
            PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
            WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
            wdOpenFormatAuto, XMLTransform:=""
        Application.Run MacroName:="CastingBook1"
        ActiveWindow.Close SaveChanges:=wdDoNotSaveChanges
        ChangeFileOpenDirectory "Y:\zzz\"
        Documents.Open FileName:= _
            "Y:\zzz\Mail Merge - Theatre, Active.docm", _
            ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
            PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
            WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
            wdOpenFormatAuto, XMLTransform:=""
        Application.Run MacroName:="theatre"
        ActiveWindow.Close SaveChanges:=wdDoNotSaveChanges
        ChangeFileOpenDirectory "Y:\zzz\"
        Documents.Open FileName:= _
            "Y:\zzz\Mail Merge - UK Casting Directors.docm", _
            ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
            PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
            WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
            wdOpenFormatAuto, XMLTransform:=""
        Application.Run MacroName:="UKcastingdirectors"
        ActiveWindow.Close SaveChanges:=wdDoNotSaveChanges
        ChangeFileOpenDirectory "Y:\zzz\"
        Documents.Open FileName:= _
            "Y:\zzz\Mail Merge - US Casting.docm", _
            ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
            PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
            WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
            wdOpenFormatAuto, XMLTransform:=""
        Application.Run MacroName:="UScasting"
        ActiveWindow.Close SaveChanges:=wdDoNotSaveChanges
        Documents.Application.DisplayAlerts = tmp
        MsgBox "All Casting Books have been updated."
End Sub

所以,我要么需要

如果有人能提供帮助,我们将不胜感激。

在不附加数据源的情况下保存您的每个文档,但修改每个文档中的 VBA 代码以执行适当的 OpenDataSource