Excel 2007 COM: Using SaveAs from PowerShell

M

Marco Shaw

Simple enough code below. If I chose something other than the default
..xlsx format to save a file, I get a prompt to save when trying to quit().

Is there a way around this? And also to force overwriting an existing
file, if found?

#remove-item c:\test_foo.xlsx
remove-item c:\test_foo.csv
$a = New-Object -comobject Excel.Application
$a.Visible = $True
$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)
$c.Cells.Item(1,1) = "A value in cell A1."
#$b.SaveAs("C:\test_foo.xlsx") <--no prompt to save when uncommented.
$b.SaveAs("C:\test_foo.csv",6)
$a.quit()

Marco

--
----------------
PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
 
J

Jim Rech

I don't know much about Powershell but try this before the quit:

$b.Saved = $True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top