这是项目浏览器显示所有工作表。 worksheet1-19是原始工作表,工作表19-37是我添加的工作表。
我尝试使用代码名称,但它显示运行时错误424。
我目前正在处理一个工作簿,该工作簿打开同一文件夹中的文件并添加到特定工作簿(其中已包含19个工作表)
现在打开文件并将其添加到工作簿后,我想运行一个应用程序(我记录的)到添加到工作簿中的新工作表。
问题是录制的应用程序会记住我添加的先前工作表的工作表名称。这意味着,当我向工作簿添加新工作表时,应用程序不会运行。
有人可以帮我这个吗?这是我运行应用程序的(记录)代码:
nil
答案 0 :(得分:0)
工作表可以通过Worksheet.CodeName property中的Worksheet.Name property,Worksheet.Index property或Worksheets collection引用。
示例:
dim w as long
for w = 1 to worksheets.count
with worksheets(w)
'do something with each worksheet
end with
next w
worksheets.add after:=worksheets(worksheets.count)
with worksheets(worksheets.count)
'do something with the new last worksheet
end with
worksheets.add before:=worksheets(1)
with worksheets(1)
'do something with the new first worksheet
end with
with worksheets("Sheet1")
'do something with the worksheet named Sheet1 on the sheet tab in the application window
end with
with Sheet1
'do something with the worksheet labeled Sheet1 in the Project Explorer
end with