0

In regard to nixda's answer in How can I set Excel to always import all columns of CSV files as Text?, how can I set the workbook name in PS when I am using this script (PowerShell script to open CSVs directly from Windows Explorer) to open a text or csv file? Using the script provided by nixda, the workbook name is book1 (the default).

I can't seem to find a good reference that discusses workbook naming in PowerShell.

Jurro
  • 28
  • 1
  • 5

1 Answers1

2

EDIT: I have clearly misunderstood your question. You want to change workbook name. I think that workbook name is set when saved. You can use ComObjects SaveAs() method:

$workbook.SaveAs("C:\Users\user\Desktop\TEST.xlsx")

By inspecting Excel.Application com object which was used in mentioned answer, it seems you can set the Excel sheet name with following code:

$excel = new-object -ComObject excel.application
$workbook = $excel.Workbooks.Add()
$workbook.ActiveSheet.Name = "TEST"

When you check it by changing Visible property from false to true:

$excel.Visible = $true

Name should change.


Additionaly, you can check Doug Finke's ImportExcel Powershell module, it provides very nice way of manipulating excel files (only new xlsx format)

https://github.com/dfinke/ImportExcel