You can avoid the need to deal with dialog boxes. Try one (or both) of these:
$a.DisplayAlerts = $False
$null = [Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
[System.Windows.Forms.Clipboard]::Clear()
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm trying to figure out how to programmatically close an excel dialog box that pops up when I'm closing a workbook.
# create an instance of excel
$a = New-Object -comobject Excel.Application
# make it visible
$a.Visible = $True
# open workbook
$b = $a.Workbooks.Open("filename.xlsx")
# There are a number of steps following, then I manually copy some data from the workbook.
# close the workbook, saving changes
$b.Close($true)
# this is the point where I see the dialog box I want to close programmatically
I don't want to save the info on the clipboard, so I want to answer No
Thanks for any assistance
Christian Bahnsen
You can avoid the need to deal with dialog boxes. Try one (or both) of these:
$a.DisplayAlerts = $False
$null = [Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
[System.Windows.Forms.Clipboard]::Clear()
Hi,
Please see if this helps
https://social.technet.microsoft.com/Forums/windowsserver/en-US/5dc5513e-09dd-4ee4-b5d6-2f1e86d12821/powershell-and-excel-cutcopymode?forum=winserverpowershell
Best Regards,
Ian
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Thanks, $a.DisplayAlerts = $False worked like a charm
Thanks also to @Ian Xue (Shanghai Wicresoft Co., Ltd.) for your reply