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

Powershell to Excel "Old format or invalid type library. (Exception from HRESULT: 0x80028018 TYPE_E_INVDATAREAD))"

$
0
0

Hi everyone,

I have a script a friend wrote & gave me written on en-US Windows 7 with French Office 2013.  The script works fine for him, however for me with English Windows 7 & English Office 2013, I get the following error with specific cmdlets

"Old format or invalid type library. (Exception from HRESULT: 0x80028018 TYPE_E_INVDATAREAD))"

the original code.

$xl=New-Object -ComObject "Excel.Application"
$xl.Visible=$True
$wb = $xl.Workbooks.Open("D:\work\file.xlsx")

I modified the script from this page to this so I could open the file, which works fine...

function Invoke([object]$m, [string]$method, $parameters)
{
$m.PSBase.GetType().InvokeMember(
$method, [Reflection.BindingFlags]::InvokeMethod, $null, $m, $parameters,$ciUS)
} 

$ciUS = [System.Globalization.CultureInfo]'en-US'

$objExcel = New-object -com Excel.Application
$objExcel.visible = $True
$ci = [System.Globalization.CultureInfo]'en-us'
$objWorkbook = Invoke $objExcel.Workbooks Open("D:\work\file.xlsx")

the problem is with the rest of the script...

$ws = $objWorkbook.Worksheets.Item(3)
$cells = $ws.Cells

$range = $ws.range("A2:Z99")
$null = $range.Delete()
$range = $null

I get the following error when calling $range.delete()

Exception calling "Delete" with "0" argument(s): "Old format or invalid type library. (Exception from HRESULT: 0x80028018 TYPE_E_INVDATAREAD))"
At line:1 char:22
+ $null = $range.Delete <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

Why would the function work for opening the file, but not for subsequent excel commands?

Thanks

Alex

P.S, anyway I can triple check my language version of Office? (Windows system locale is def English (United States)




Viewing all articles
Browse latest Browse all 15028

Trending Articles



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