请问excel中如果更改工作表名称就会使该工作表原来的vba失效,写什么代码才不会让这样的事发生呢
答案:4 悬赏:0
解决时间 2021-02-28 02:07
- 提问者网友:浪女天生ˇ性情薄
- 2021-02-27 13:58
请问excel中如果更改工作表名称就会使该工作表原来的vba失效,写什么代码才不会让这样的事发生呢
最佳答案
- 二级知识专家网友:狠傷凤凰
- 2021-02-27 14:56
不要使用工作表名,使用sheets(x)
全部回答
- 1楼网友:时光不老我们不分离
- 2021-02-27 16:05
)Sub a()
MsgBox Sheet1.Name
MsgBox Sheets("Sheet1".Name
MsgBox Sheets(1)
- 2楼网友:甜野猫
- 2021-02-27 15:21
答:可以。<br>复制下面代码到vb编辑器里,运行"modifysheetname"程序。程序会弹出对话框来让你选择文件,修改完成后保存在原位置。<br>private function getdirectory()<br> dim fd as filedialog<br> set fd = application.filedialog(msofiledialogfolderpicker)<br> with fd<br> if .show = -1 then<br> getdirectory = .selecteditems(1)<br> else<br> getdirectory = ""<br> end if<br> end with<br>end function<br>sub modifysheetname()<br> dim vfiles as variant<br> dim nindex as integer<br> dim wkb as workbook<br> dim totalfiles as integer<br><br> application.displayalerts = false<br> vfiles = application.getopenfilename(filefilter:="excel工作簿(*.xls*),*.xls*", _<br> title:="选择待转换的文件", multiselect:=true)<br> if not isarray(vfiles) then exit sub<br> totalfiles = ubound(vfiles)<br> for nindex = 1 to totalfiles<br> set wkb = getobject(vfiles(nindex))<br> with wkb<br> windows(.name).visible = true<br> .sheets("sheet1").name = "summary"<br> .close savechanges:=true<br> end with<br> set wkb = nothing<br> next nindex<br> application.displayalerts = true<br> msgbox "修改完成!共计" & totalfiles & "个文件"<br>end sub
- 3楼网友:啵啵桃汀
- 2021-02-27 15:12
不要用如Sheets("Sheet1")这样带引号的
用序号Sheets("Sheet1")用Sheets(1)替代
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯