gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 05:30:46 27 4
gpt4 key购买 nike

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

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

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?

我需要尽可能简单,以免用户因为困惑而选择“否”。 VBA 如何自动继续并接受数据放置,就像他们选择"is"一样?

我尝试只使用以下代码来阻止警报,希望它会默认"is"并继续,但它没有用。

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

关于excel VBA 在邮件合并期间提示时自动选​​择是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11301716/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com