According to the google searches that I have done so far, I haven’t seen an instance where ‘SaveAs’ method doesn’t exist.
I am trying to open a tab delimited file (.txt), open it in excel and then save it as XLSX
The following is my code
$Excel = New-Object -Com Excel.Application $Excel.Visible = $True $ExcelFile = "E:FOLDERSAMPLE.TXT" $Workbook = $Excel.Workbooks.Open($ExcelFile)
Now to set the xlFixedFormat
#$xlFixedFormat = [Microsoft.Office.Interop.Excel.XlFileFormat]::xlWorkbookDefaultxlXMLSpreadsheet
For xls
#$xlFixedFormat = [Microsoft.Office.Interop.Excel.XlFileFormat]::xlOpenXMLWorkbook
For xlsx according to
“XLSX is Excel Microsoft Office Open XML Format Spreadsheet .. So you may use ‘xlXMLSpreadsheet’ for xlFileFormat parameter.”
$xlFixedFormat = [Microsoft.Office.Interop.Excel.XlFileFormat]::xlWorkbookDefault
For xlsx, according to
http://stackoverflow.com/questions/22560483/powershell-script-to-convert-txt-to-xlsx
$Excel.Save("E:FOLDERSAMPLE.xlsx")
This line works without any issue, unless the file already exists, but that can be solved easily.
But when I try to run the SaveAs Method,
$Excel.SaveAs("E:FOLDERSAMPLE.xlsx",$xlFixedFormat)
I get a error as
Method invocation failed because [Microsoft.Office.Interop.Excel.ApplicationClass] does not contain a method named ‘SaveAs’.
As far as I can tell, I don’t have
Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel (in microsoft.office.tools.excel.dll)
How do I download this file? Do I need to download this file?
My PSVersion is:
PSVersion 4.0
My Excel is Microsoft Office Professional Plus 2010
and Windows 7
submitted by /u/DarthFarious
[link] [comments]
The post Excel.ApplicationClass doesn’t have a method ‘SaveAs’ appeared first on How to Code .NET.