【发布时间】:2016-12-28 14:42:35
【问题描述】:
具有 26 张工作表的 Excel 2016 工作簿均命名为 Jan 2、Jan 16、Jan 30、Feb 13 等。在每个工作表单元格 B1 上也有相同的信息,分别是 1 月 2 日、1 月 16 日、1 月 30 日、2 月 13 日。在每张纸上还有更多的日期信息,工作表 Jan 2, B3 具有该周的第一个日期(1 月 2 日),然后在 1 月 3 日、1 月 4 日、1 月 5 日的两个星期期间进行,在 M3 1 月 14 日结束,仅跳过星期日。我想让工作簿打开到其中包含有关今天日期的信息的工作表。因此,当我在 5 月 19 日打开它时,例如打开它的工作表将是 5 月 8 日。
Dim ws As Worksheet
Dim mnth As String, dte As String, mday As String
mday = Now() - Weekday(Now(), 3)
mnth = Month(mday)
dte = Day(mday) tabstr = mnth & " " & dte
For Each ws In Worksheets
If ws.Name = tabstr Then ws.Select Exit For
End If
Next ws
【问题讨论】:
-
欢迎来到 S.O!你试过什么吗?如果是,请提供代码。看看tour 和how to ask。友情提示:StackOverflow 不是“我们为您编码”的服务提供商。 Introduction to VBA 或 Mid-Advanced Tutorials 和我的 personal favorite
-
Dim ws As Worksheet Dim mnth As String, dte As String, mday As String mday = Now() - Weekday(Now(), 3) mnth = Month(mday) dte = Day(mday) tabstr = mnth & " " & dte For Each ws In Worksheets If ws.Name = tabstr Then ws.Select Exit For End If Next
-
我尝试了上面的代码,但我认为它把它当作#的“1 2”,我需要它把它看作“jan 2”
-
您使用了错误的函数:month() 将返回它的“#”,月份名称使用 monthname
-
Format(Month(mday),"mmm")也可以使用