【问题标题】:I have an excel workbook with multiple tabs and want to select a tab using vba that has a date that changes each week我有一个带有多个选项卡的 excel 工作簿,并且想使用 vba 选择一个选项卡,该选项卡的日期每周都会更改
【发布时间】:2020-08-12 18:05:20
【问题描述】:

我每周下载一张 Excel 表格,标签名称中包含今天的日期,显然每周都会发生变化。我将其他 excel 导出添加到同一个工作簿,所以我有 3 个不同的选项卡,其中一个是当前日期的选项卡。如何设置我的 vba 宏以每周在 Excel 工作簿中选择选项卡,即使日期发生变化?我可以使用通配符吗?

Here is an image of the tabs. You can see that the first tab has a date. Only the date changes each week but the first part stays the same.

【问题讨论】:

  • 遍历选项卡并找到名称以“任务开始日期”开头的选项卡
  • 添加到@TimWilliams 评论;根据您的示例,如果您的工作表is always the first worksheet(tab),您可以使用worksheet Index number,例如Sheets(1) 不使用通配符或名称。

标签: excel vba


【解决方案1】:

这是一种方法...

Sub whatever()
Dim mySheet As Worksheet
For Each mySheet In ActiveWorkbook.Worksheets
    If mySheet.Name Like "Sheet*" Then
        mySheet.Select
        Exit For
    End If
Next mySheet
End Sub

我在下面的工作簿上对此进行了测试。选择“其他东西”开始。然后它找到了“Sheet123456789”

【讨论】:

  • 嗨@ari_gasparoni,非常欢迎您。如果您不介意,请单击以接受答案作为解决方案。祝你有美好的一天 =)
猜你喜欢
  • 2020-04-11
  • 1970-01-01
  • 1970-01-01
  • 2023-04-09
  • 2021-05-10
  • 2019-01-04
  • 1970-01-01
  • 1970-01-01
  • 2015-07-30
相关资源
最近更新 更多