2

Hello i tried with that code

$e = New-Object -ComObject "Excel.Application"
$e.Visible = $true
$ew = $e.Workbooks.Open("C:\Users\mich\14_50_33__5_Pt_50_sie_2011.xls")
$ew.SaveAs("C:\Users\mich\Documents\test", "Excel.XlFileFormat.xlHtml")

What do i do wrong?


Here is my own working code:

$xlExcelHTML = 44
$Excel = New-Object -ComObject "Excel.Application"
$Excel.Visible = $true
$WorkBook = $Excel.Workbooks.Open("C:\Users\mich\14_50_33__5_Pt_50_sie_2011")
$WorkSheet = $WorkBook.Worksheets.Item(1)
$WorkBook.SaveAs("C:\temp\test8",$xlExcelHTML)

Here is a link for format extensions code: http://msdn.microsoft.com/en-us/library/bb241279(office.12).aspx

deadfish
  • 11,996
  • 12
  • 87
  • 136

1 Answers1

5

This is working for me. There are 12 arguments you need to pass to the saveAs method. Fill each unspecified arguments with [type]::Missing

$xlHtml = 44
$missing = [type]::Missing
$xl = New-Object -ComObject Excel.Application
$xl.Visible = $true
$wb = $xl.Workbooks.Open('d:\book1.xlsx')
$xl.ActiveWorkbook.SaveAs('d:book1.html',$xlHtml,$missing,$missing,$missing,$missing,$missing,$missing,$missing,$missing,$missing,$missing)
$xl.Quit()
Shay Levy
  • 121,444
  • 32
  • 184
  • 206
  • however i wrote something similat – deadfish Aug 07 '11 at 13:25
  • 1
    You're right, for some reason I missed the working example part. I guess the your first attempt doesn't work because you didn't specify which sheet to save and that "Excel.XlFileFormat.xlHtml" is not resolved to the correct value. – Shay Levy Aug 07 '11 at 14:40