我的目标: 创建一个新选项卡并在函数中命名。
我的问题: 当我在函数内部创建新选项卡时,我无法命名该选项卡。
注意: 当我在函数之外创建选项卡时,它会正确命名。
我的代码:
Function Function_CreateWorksheets($Worksheets) {
ForEach ($Worksheet in $Worksheets) {
$Excel_Count_Worksheet++
If ($Excel_Count_Worksheet -gt 3) {$Script:Excel.Worksheets.Add() |Out-Null}
$Script:Excel.Worksheets.Item($Excel_Count_Worksheet).Name = $Worksheet
}
}
#Load-Module -Module grouppolicy -Reload
Get-Variable Excel_* |Remove-Variable -Force
#Create Excel Com Object
$Excel = New-Object -com Excel.Application
# Make the Excel Application Visible to the end user
$Excel.visible = $True
# Create a WorkBook inside the Excel application
# that we can start manipulating.
$Excel_Workbook = $Excel.Workbooks.Add()
$Action_CreateWorksheet =
#=======================================================
# Now that we have a workbook we need to create some
# additional worksheets (Tabs) beyond that initial 3
# that are created when the workbook is opened.
#=======================================================
#$Temp_MakeWorkSheet = $Excel.Worksheets.Add()
#=======================================================
# Once all the sheets are created each of the worksheets
# need to be assigned to a variable so they can be
# manipulated.
#=======================================================
Function_CreateWorksheets -Worksheets "System Summary","Test1","Test2","Test3","Test4"