我正在尝试在最后一个工作表之后将工作表名称分配给工作表。但是,我不断收到编译错误:语法错误这是编译器说它有问题的代码。确切的行是添加工作表的行。
logic = "S_ANY"
allowClear = "NO"
arrayIndex = 0
flowName = flow
flowSplit = Split(flowName, "_")
flowNameSuffix = flowSplit(0)
newWorkSheetName = "Test_Master_" & flowNameSuffix
Set ws = Workbooks.Open(pathToFile).Worksheets("Test_Master")
Set ws2 = Workbooks.Open(pathToXl)
ws2.Sheets.Add(After:=ws2.Sheets.Count)).Name = newWorkSheetName
ws2定义为工作簿,newWorkSheetName定义为String。在此代码之前只是变量声明。我不确定我在这里做错了什么。任何帮助都会很棒!
答案 0 :(得分:0)
试试这个:
With ws2.Sheets.Add(After:=ws2.Sheets(ws2.Sheets.Count))
.Name = "XYZ"
End With
复制此:
Set ws = Workbooks.Open(pathToFile).Worksheets("Test_Master")
Set ws2 = Workbooks.Open(pathToXl)
With ws2.Sheets.Add(After:=ws2.Sheets(ws2.Sheets.Count))
.Name = newWorkSheetName
End With
如果它仍然引发错误 - 取消注释With-Block并查看您的宏是否正常工作。
"后:="感谢实际的Sheet-Objekt。
BR