Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell opening and saving Excel 2013 file

$
0
0

I'm having an issue with Powershell 3.0 saving an Excel 2013 file. My script opens an existing Excel file, adds data to the next free row before saving the file and sending it via email as an attachment. No matter what I try the Excel process stays open, if I kill the process the script runs the next time I execute it but does not add any data.

Based on other threads I tried the following:

$file="c:\scripts\mbx_connections.xlsx"
$xl=New-Object -ComObject "Excel.Application"
$wb=$xl.Workbooks.Open($file)
$ws=$wb.ActiveSheet
$xl.DisplayAlerts = $FALSE

$cells=$ws.Cells
$rows = $ws.UsedRange.Rows.Count

<snip>

$wb.SaveAs("c:\scripts\mbx_connections.xlsx")

$wb.Close()
$xl.Quit()

[System.Runtime.Interopservices.Marshal]::ReleaseComObject($wb)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($xl)
Remove-Variable wb
Remove-Variable xl

Are there any other ways to close the file or known issues with using Excel 2013?

Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>