根据当前日期打开特定表格 [英] Open specific sheet according to current Date

查看:126
本文介绍了根据当前日期打开特定表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一本excel工作簿中有52张照片,每张照片都按照日期的顺序命名,格式为:11-3,11-10,11-17,11-24。这一天与星期一相当。

I have 52 sheets in an excel workbook, and each one is named according to month-date in the format: 11-3, 11-10, 11-17, 11-24. The day corresponds with the Monday of the week.

我的目标是将代码根据日期打开工作簿到工作表。所以例如,如果我今天(11月7日)打开,那么它将打开到表11-3。如果我在11月7日下周打开它将打开11-10张。我尝试了几种不起作用的不同方法。如果有人有建议,将不胜感激。

My goal is to have code that will open the workbook to a sheet according to the date. So for example, if I opened it today (Nov 7) then it would open to sheet 11-3. If I opened it next week on Nov 7 it would open the 11-10 sheet. I've tried several different methods that don't work. If anyone has a suggestion it would be greatly appreciated.

谢谢

推荐答案

p>这样的事情可能在ThisWorkbook模块的Workbook_Open事件中起作用。

Something like this might work in the ThisWorkbook module's, Workbook_Open event.

Private Sub Workbook_Open()

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
End Sub

这篇关于根据当前日期打开特定表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆