Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Saving a file in Excel keeps popping SaveAs dialog box

$
0
0

I've been struggling with this for a couple of hours now. Can someone please help !!

I'm simply trying to figure out how to use the SaveAs method to save an Excel workbook. But the SaveAs dialog keeps popping up. I've even set the DisplayAlerts method to False but it doesn't seem to work. Not sure if the version of Office matters but I'm using Office 2010.

$excel = New-Object -ComObject Excel.Application

$xlOpenXMLWorkbook=[int]51

$excel.Visible = $true

$wb = $excel.Workbooks.Add()

$ws = $wb.Worksheets.Item(1)

$ws.Name = "test"

$excel.DisplayAlerts = $false

$excel.ActiveWorkbook.SaveAs($env:tmp + "\myfile.xlsx", $xlOpenXMLWorkbook)

$excel.Saved = $true

$excel.ActiveWorkbook.Close()

$excel.Quit()

$excel = $null 

 [System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)

Remove-Variable $excel

[GC]::Collect() 


Viewing all articles
Browse latest Browse all 6937

Trending Articles