[英]Excel Vba to open a file using .range as the directory
I have a macro that needs to open files but the problem is everyday it is in a new folder labeled according to the day.我有一个需要打开文件的宏,但问题是每天都在一个按日期标记的新文件夹中。 Example today would be C:\\WORK\\122315\\fileexample.xlsx
今天的例子是 C:\\WORK\\122315\\fileexample.xlsx
How I usually open files with dates is by entering the date in cell A1 as a TEXT "122315" then use Date1 = Range("A1").Value in vba.我通常打开带有日期的文件的方法是在单元格 A1 中输入日期作为文本“122315”,然后在 vba 中使用 Date1 = Range("A1").Value。 My question is what do I do if the date is not in the file, but in the subfolder?
我的问题是如果日期不在文件中,而是在子文件夹中,我该怎么办?
Date1 = Range("A1").Value
ChDir "C:\WORK\Date1"
Workbooks.Open Filename:= _
"C:\WORK\Date1\fileexample.xlsx"
Workbooks.Open Filename:="C:\WORK\" & Range("A1").Value & "\fileexample.xlsx"
仅供参考,如果您将完整文件路径传递给Open
则不需要使用ChDir
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.