【问题标题】:Excel VBA get the name of the next sheet after currentExcel VBA获取当前工作表之后的下一个工作表的名称
【发布时间】:2016-09-19 05:14:00
【问题描述】:

Excel VBA 中有没有办法获取ActiveSheet 之后的下一张工作表的名称?

例如,假设我的电子表格有 4 张工作表,我想创建一个宏,在当前工作表(本例中为Sheet1)中插入下一个电子表格的名称(Sheet2)。像这样:

【问题讨论】:

    标签: vba excel macros


    【解决方案1】:

    Activesheet.Index 会给你活动工作表的位置,所以:

    ActiveSheet.Range("A1")= ActiveSheet.Parent.Sheets(Activesheet.Index + 1).Name
    

    您应该添加检查活动表不是最后一个...

    【讨论】:

      【解决方案2】:

      这里只是一个小样本。

      Dim sh As Worksheet, shprv As Worksheet, shnext As Worksheet
      //make sure that use "as Worksheet" after every variable you declare
      
      Set sh = ActiveSheet     //always use "Set" before since these variables are "Object type", only by this their values can be set correctly
      Set shprv = sh.Previous
      Set shnext = sh.Next
      

      在这种情况下,sh 的值将是Sheet1,如您提供的图片,
      shnext 的值将是 Sheet2
      但是shprv 将没有任何价值,因为Sheet1 之前没有工作表。

      【讨论】:

        猜你喜欢
        • 2012-08-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多