专栏名称: 完美Excel
Excel与VBA技术学习与实践
目录
相关文章推荐
今天看啥  ›  专栏  ›  完美Excel

自动生成操作工作表的通用代码

完美Excel  · 公众号  · Excel  · 2024-12-11 05:56
    

文章预览

学习Excel技术,关注微信公众号: excelperfect 标签: VBA 在编写代码时,通常需要声明工作表变量、设置一些环境变量状态等,例如声明工作表变量: Dim wsSHEET1 as Worksheet 然后给其赋值: Set wsSHEET1 = wb.Sheets("Sheet1") 下面的代码可以自动生成这些通用代码: Sub CreateWorksheetGenCoding() Dim ws As Worksheet Dim wsName As String Dim sName As String Dim sNames As String Dim blnSheetsWanted As Boolean c00 = "Dim ws" c01 = " as Worksheet" c02 = "Set ws" c03 = " = wb.Sheets(""" c04 = " = Nothing" sNames = "/" For i = 1 To ActiveWorkbook.Sheets.Count Set ws = ActiveWorkbook.Sheets(i) wsName = ws.Name ws.Activate sName = ""    Do sName  = Trim(UCase(Application.InputBox( _      IIf(ws.Visible  =  xlSheetHidden, "隐藏的 - "  &  vbCr  &  vbCr, IIf(ws.Visible = xlSheetVeryHidden, "深度隐藏的 - "  &  vbCr  &  vbCr ………………………………

原文地址:访问原文地址
快照地址: 访问文章快照
总结与预览地址:访问总结与预览