宏以选择当前日期不是标准格式的文件夹中的文件

时间:2015-03-26 22:16:22

标签: excel date excel-vba vba

您能告诉我如何修改以下代码,以便自动打开它吗?

 Range("A1:AK1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Range("A1").Select
    Workbooks.Open Filename:= _
        "Y:\DentalConsumables\Company\DMC\DMC - Planning & Materials\Build Plan DTW Reports\DataWHSreports\2015-03-26_DWHS_PEN EU Fixed.xlsx" _
        , UpdateLinks:=0, Notify:=False
    ActiveWindow.SmallScroll Down:=12

1 个答案:

答案 0 :(得分:1)

如果只有日期部分发生变化,您可以尝试一下:

编辑1:关闭已打开的文件

Dim curDate As String, Fname As String
curDate = Format(Date, "yyyy-mm-dd") ' returns the current date in specified format
Dim wb As Workbook ' add a variable to pass your workbook object

Fname = "Y:\DentalConsumables\Company\DMC\DMC - Planning & Materials\" _
        & "Build Plan DTW Reports\DataWHSreports\" & curDate 
        & "_DWHS_PEN EU Fixed.xlsx"
Set wb = Workbooks.Open(FileName:=Fname, UpdateLinks:=False, Notify:=False)

' ~~> Other cool stuff goes here

wb.Close False ' Close the opened workbook; False indicates to not save changes