2

How does one specify the options? This works $workbook.worksheets.Add() but I want to specify a worksheet to add this new one after. That's the second of four possible options:.Add(Before, After, Count, Type). I can't seem to figure out what the proper syntax in Powershell is. If I get it wrong, there's no error, but the worksheet is not created. For example, $workbook.worksheets.Add(,$lastSheet) does not work. $lastSheet of course is a sheet object. I instantiated that with $sheet = $workbook.ActiveSheet $lastSheet = $sheet

1
  • I tried to figure this out once, and eventually gave up and just created the sheet at the default location and moved it later. Commented Sep 8, 2016 at 23:33

1 Answer 1

3
$workbook.worksheets.Add([System.Reflection.Missing]::Value,$lastsheet)

Apparently the [System.Reflection.Missing]::Value can be used to represent a value in this kind of construction because a null is not allowed.

Sign up to request clarification or add additional context in comments.

1 Comment

Kind of janky. I wonder if there is a better way to do this kind of stuff with Office applications. Write it in VBA and then call that somehow with Powershell? I don't know if that would flow anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.