<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How Can I Use Windows PowerShell to Automate Microsoft Excel?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2006/09/08/how-can-i-use-windows-powershell-to-automate-microsoft-excel.aspx</link><description>Hey, Scripting Guy! How can I use Windows PowerShell to automate Microsoft Excel? -- MW 
 Hey, MW. Yes, it’s true: the week of November 6-10, 2006 will be Windows PowerShell Week on TechNet, with the Scripting Guys presenting a series of webcasts (one</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: How Can I Use Windows PowerShell to Automate Microsoft Excel?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2006/09/08/how-can-i-use-windows-powershell-to-automate-microsoft-excel.aspx#3535373</link><pubDate>Thu, 29 Nov 2012 04:03:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3535373</guid><dc:creator>Meister1867</dc:creator><description>&lt;p&gt;For Windows 8, I had to do a slight modification... &amp;nbsp;I can&amp;#39;t save to the C-drive in Windows 8 using PowerShell, so....&lt;/p&gt;
&lt;p&gt;# Create directory if does not exist&lt;/p&gt;
&lt;p&gt; if ((Test-Path -Path &amp;quot;C:\Scripts&amp;quot;) -ne $True)&lt;/p&gt;
&lt;p&gt; {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;New-Item C:\Scripts -type directory&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;$a = New-Object -comobject Excel.Application&lt;/p&gt;
&lt;p&gt;$a.Visible = $True&lt;/p&gt;
&lt;p&gt;$a.DisplayAlerts = $false&lt;/p&gt;
&lt;p&gt;$b = $a.Workbooks.Add()&lt;/p&gt;
&lt;p&gt;$c = $b.Worksheets.Item(1)&lt;/p&gt;
&lt;p&gt;$c.Cells.Item(1,1) = &amp;quot;A value in cell A1.&amp;quot;&lt;/p&gt;
&lt;p&gt;$b.SaveAs(&amp;quot;C:\Scripts\Test.xlsx&amp;quot;)&lt;/p&gt;
&lt;p&gt;$a.Quit()&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3535373" width="1" height="1"&gt;</description></item><item><title>re: How Can I Use Windows PowerShell to Automate Microsoft Excel?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2006/09/08/how-can-i-use-windows-powershell-to-automate-microsoft-excel.aspx#3375156</link><pubDate>Wed, 15 Dec 2010 09:06:45 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3375156</guid><dc:creator>powersheller</dc:creator><description>&lt;p&gt;If I have my PowerShell running to do Excel automation using Windows Scheduler, how do I avoid conflict with other Excel users on the same machine when my job is running? The problem is other Excel users will get affect by my job when they are using Excel while the job is running. Thanks in advance.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3375156" width="1" height="1"&gt;</description></item><item><title>re: How Can I Use Windows PowerShell to Automate Microsoft Excel?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2006/09/08/how-can-i-use-windows-powershell-to-automate-microsoft-excel.aspx#3351297</link><pubDate>Mon, 23 Aug 2010 07:40:07 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3351297</guid><dc:creator>arnold</dc:creator><description>&lt;p&gt;hello,&lt;/p&gt;
&lt;p&gt;pls, how i can us the methode : .Calculate, .CalculateFull.....&lt;/p&gt;
&lt;p&gt;thx&lt;/p&gt;
&lt;p&gt;my best regard&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3351297" width="1" height="1"&gt;</description></item><item><title>re: How Can I Use Windows PowerShell to Automate Microsoft Excel?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2006/09/08/how-can-i-use-windows-powershell-to-automate-microsoft-excel.aspx#3337091</link><pubDate>Wed, 09 Jun 2010 15:17:09 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3337091</guid><dc:creator>5lb_Bass</dc:creator><description>&lt;p&gt;I&amp;#39;m running the code in your example,&lt;/p&gt;
&lt;p&gt;$a = New-Object -comobject Excel.Application&lt;/p&gt;
&lt;p&gt;$a.Visible = $True&lt;/p&gt;
&lt;p&gt;$b = $a.Workbooks.Add()&lt;/p&gt;
&lt;p&gt;$c = $b.Worksheets.Item(1)&lt;/p&gt;
&lt;p&gt;$c.Cells.Item(1,1) = &amp;quot;A value in cell A1.&amp;quot;&lt;/p&gt;
&lt;p&gt;$b.SaveAs(&amp;quot;C:\Scripts\Test.xls&amp;quot;)&lt;/p&gt;
&lt;p&gt;$a.Quit()&lt;/p&gt;
&lt;p&gt;and generate the following error. &amp;nbsp;Any ideas?&lt;/p&gt;
&lt;p&gt;PS H:\&amp;gt; c:\data\ACE-IT\projects\TabletConfiguration\test.ps1&lt;/p&gt;
&lt;p&gt;Exception calling &amp;quot;Add&amp;quot; with &amp;quot;0&amp;quot; argument(s): &amp;quot;The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))&amp;quot;&lt;/p&gt;
&lt;p&gt;At C:\data\ACE-IT\projects\TabletConfiguration\test.ps1:5 char:22&lt;/p&gt;
&lt;p&gt;+ $b = $a.Workbooks.Add &amp;lt;&amp;lt;&amp;lt;&amp;lt; ()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ CategoryInfo &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: NotSpecified: (:) [], MethodInvocationException&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ FullyQualifiedErrorId : ComMethodTargetInvocation&lt;/p&gt;
&lt;p&gt;You cannot call a method on a null-valued expression.&lt;/p&gt;
&lt;p&gt;At C:\data\ACE-IT\projects\TabletConfiguration\test.ps1:6 char:24&lt;/p&gt;
&lt;p&gt;+ $c = $b.Worksheets.Item &amp;lt;&amp;lt;&amp;lt;&amp;lt; (1)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ CategoryInfo &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: InvalidOperation: (Item:String) [], RuntimeException&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ FullyQualifiedErrorId : InvokeMethodOnNull&lt;/p&gt;
&lt;p&gt;You cannot call a method on a null-valued expression.&lt;/p&gt;
&lt;p&gt;At C:\data\ACE-IT\projects\TabletConfiguration\test.ps1:8 char:14&lt;/p&gt;
&lt;p&gt;+ $c.Cells.Item &amp;lt;&amp;lt;&amp;lt;&amp;lt; (1,1) = &amp;quot;A value in cell A1.&amp;quot;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ CategoryInfo &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: InvalidOperation: (Item:String) [], RuntimeException&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ FullyQualifiedErrorId : InvokeMethodOnNull&lt;/p&gt;
&lt;p&gt;You cannot call a method on a null-valued expression.&lt;/p&gt;
&lt;p&gt;At C:\data\ACE-IT\projects\TabletConfiguration\test.ps1:9 char:10&lt;/p&gt;
&lt;p&gt;+ $b.SaveAs &amp;lt;&amp;lt;&amp;lt;&amp;lt; (&amp;quot;C:\temp\Test.xls&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ CategoryInfo &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: InvalidOperation: (SaveAs:String) [], RuntimeException&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ FullyQualifiedErrorId : InvokeMethodOnNull&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3337091" width="1" height="1"&gt;</description></item><item><title>re: How Can I Use Windows PowerShell to Automate Microsoft Excel?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2006/09/08/how-can-i-use-windows-powershell-to-automate-microsoft-excel.aspx#3319563</link><pubDate>Wed, 17 Mar 2010 13:09:57 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3319563</guid><dc:creator>shivkhare</dc:creator><description>&lt;p&gt;I am running below code -&lt;/p&gt;
&lt;p&gt;[System.Reflection.Assembly]::LoadWithPartialName(&amp;quot;Microsoft.Office.Interop.Excel&amp;quot;)&lt;/p&gt;
&lt;p&gt;[System.Reflection.Assembly]::LoadWithPartialName(&amp;quot;Microsoft.Office.Core&amp;quot;)&lt;/p&gt;
&lt;p&gt;[Microsoft.Office.Interop.Excel.Application]$xl = &amp;nbsp; new-object Microsoft.Office.Interop.Excel.ApplicationClass&lt;/p&gt;
&lt;p&gt; $file=&amp;quot;D:\test\test.csv&amp;quot;&lt;/p&gt;
&lt;p&gt; $xl.visible = $true&lt;/p&gt;
&lt;p&gt; $wbk = $xl.Workbooks.Open(&amp;quot;$file&amp;quot;)&lt;/p&gt;
&lt;p&gt; $wks = $wbk.worksheets.item(1)&lt;/p&gt;
&lt;p&gt; $r1=[Microsoft.Office.Interop.Excel.IRange]$wks.Range(&amp;quot;A1:D1&amp;quot;)&lt;/p&gt;
&lt;p&gt; $r2=[Microsoft.Office.Interop.Excel.IRange]$wks.Range(&amp;quot;A2:D2&amp;quot;)&lt;/p&gt;
&lt;p&gt; #Commented code&lt;/p&gt;
&lt;p&gt; #$mis = [System.Reflection.Missing]::Value;&lt;/p&gt;
&lt;p&gt; #$xl.Union($r5, $r6, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis, $mis)&lt;/p&gt;
&lt;p&gt;.............&lt;/p&gt;
&lt;p&gt;It throws below error while I try to typecast _ComObject returned to IRange &lt;/p&gt;
&lt;p&gt;Error message -&lt;/p&gt;
&lt;p&gt; $r1=[Microsoft.Office.Interop.Excel.IRange]$wks.Range &amp;lt;&amp;lt;&amp;lt;&amp;lt; (&amp;quot;A1:D1&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ CategoryInfo &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: NotSpecified: (:) [], RuntimeException&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;+ FullyQualifiedErrorId : RuntimeException&lt;/p&gt;
&lt;p&gt;Typecasting is required otherwise the next command to union two range (commented code) fails with same error.&lt;/p&gt;
&lt;p&gt;I am stuck on it. Please advice.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3319563" width="1" height="1"&gt;</description></item><item><title>re: How Can I Use Windows PowerShell to Automate Microsoft Excel?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2006/09/08/how-can-i-use-windows-powershell-to-automate-microsoft-excel.aspx#3315686</link><pubDate>Fri, 26 Feb 2010 19:17:07 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3315686</guid><dc:creator>coderover</dc:creator><description>&lt;p&gt;How can I use PowerShell to clean up Carriage Returns and slashes from an Excel spreadsheet before converting it to a CSV?&lt;/p&gt;
&lt;p&gt;Perhaps using the clean function? or invoking something similar to CTRL+H and passing the CTRL+J carriage return representation?&lt;/p&gt;
&lt;p&gt;Your assistance is greatly appreciated.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3315686" width="1" height="1"&gt;</description></item></channel></rss>