InputBox函数来编辑宏

时间:2018-06-26 18:34:29

标签: excel vba inputbox

Windows("XXX Consolidated PL 03312018.xlsx").Activate
ActiveCell.Offset(187, 8).Range("A1").Select
Selection.End(xlToLeft).Select
Selection.End(xlToLeft).Select

如何创建宏或InputBox函数以更改数字“ 03312018”?

数字表示日期。每个月电子表格都会变化,因此我想手动输入新数字。

2 个答案:

答案 0 :(得分:1)

类似的事情会起作用。尽管您可能想在继续执行代码之前先验证条目:

Dim MyDate as Variant
MyDate = Inputbox ("Input Date Serial")

Windows("XXX Consolidated PL " & MyDate & ".xlsx").Activate

答案 1 :(得分:1)

类似的东西:

Option Explicit 
Public Sub test()
    Dim wkbk As String, dateVar As String
    'dateVar = "03312018"
    dateVar = Application.InputBox("Enter date string")
    If dateVar = vbNullString Then Exit Sub
    wkbk = "XXX Consolidated PL " & dateVar & ".xlsx"
    On Error GoTo Errhand
    Windows(wkbk).Activate
    'other code
    Exit Sub
Errhand:
    If Err.Number <> 0 Then
        Select Case Err.Number
        Case 9
            MsgBox "Workbook not found"
            'Other handling
        End Select
    End If
End Sub