I want to automate the Excel process of Data → Import Text File → text import wizard
How do I find the PowerShell name for these menus?
Here i
If I understood your question, you are looking at a way to import a CSV file directly into Excel.
I use the Open()
method of the $excel.workbooks object.
$excel = new-object -comobject excel.application
$file = get-item "d:\scripts\test.csv"
$excel.Visible=$true
$excel.displayalerts = $False
$wb = $excel.workbooks.open($file)
If that doesn't work, I use files I rename the .CSV file to .TXT, and open them with OpenText
UPDATED to use '|' as delimiter
$wb = $excel.Workbooks.OpenText(
"mycsv.txt", # file to open
[Microsoft.Office.Interop.Excel.XlPlatform]::xlWindows,
1, # start from row 1
[Microsoft.Office.Interop.Excel.XlTextParsingType]::xlDelimited,
[Microsoft.Office.Interop.Excel.XlTextQualifier]::xlTextQualifierDoubleQuote,
$false, # Consecutive Delimiter
$false, # tab
$false, # semicolon
$false, # comma
$false, # space
$true, # use other
'|')
Don't use OpenText
with .CSV files directly, rename them first. Excel seems to work with CSV named files differently.