什么更新会打开我的工作簿到今天的日期?

时间:2017-01-11 17:41:32

标签: excel vba excel-vba

我希望我的工作簿能够在今天的日期单元格中打开。 2017年的日期列在第10行。我的宏列在下面,但在行上包含语法错误 'x =格式(日期,“短日期”)'

Private Sub Workbook_OpenDate()

    Dim wb As Workbook, wb1 As Workbook
    Dim LastRow As Long

    Set wb = Workbooks("2017 Capacity Planner.xlsm")

    Worksheets("Dashboard").Select
    x = Format(Date, "Short Date")

    On Error Resume Next
    Worksheets(“Dashboard”).Row(10).Find(What:=x, LookIn:=xlValues).Activate
    Application.Goto Selection, True

End Sub

1 个答案:

答案 0 :(得分:3)

你还在使用魔术引号。即使你删除了,你也会在行上出现错误438.Row(10)。然后在发现另一个错误是等待什么都没有找到。更改你的代码:

Sub test()

    Dim rng As Range
    Dim x As String

    Dim wb As Workbook, wb1 As Workbook
    Dim LastRow As Long

    Set wb = Workbooks("2017 Capacity Planner.xlsm")

    Worksheets("Dashboard").Select
    x = (Format(Date, "Short Date"))

    Set rng = Worksheets("Dashboard").Rows(10).Find(What:=x, LookIn:=xlValues)

    If Not rng Is Nothing Then
        rng.Parent.Activate
        rng.Select
    End If


End Sub