在我尝试在同一个文件上第二次运行我的 Powershell 脚本后,我得到一个“名称冲突”对话框。我知道这个错误与我自动过滤文件有关。如果我从不使用 autofiter,则不会显示对话框。我究竟做错了什么?这是代码:
$excel = new-object -comobject excel.application
$excel.DisplayAlerts = $false
$workbook = $excel.Workbooks.open("testtabelle1.xlsx")
Trap {"Worksheet problems..."} $workbook.Worksheets.Item(1) | Out-Null
$from = ">0"
$to = "<2"
$workbook.ActiveSheet.Range("D:D").AutoFilter(1, $from, 1, $to) > $null
#Reset Selection and close file
#$workbook.ActiveSheet.Range("A1").Select() | Out-Null
$workbook.Save()
$excel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)