[英]Excel: Macro to check folder for new files (based on date in a cell)
I have a macro that needs ran once a day. 我有一个宏,每天需要运行一次。 It needs to check a folder (this can be specified within the VBA, as it should not change) and then see if there are any new files.
它需要检查一个文件夹(可以在VBA中指定该文件夹,因为它不应更改),然后查看是否有任何新文件。
Currently, this Excel VBA Program prompts the user to select a file. 当前,此Excel VBA程序提示用户选择文件。 It then does things to the file, and saves the date and shift (from the filename string) into cells on sheet one.
然后,它对文件进行处理,并将日期和日期(从文件名字符串中移出)保存到第一页的单元格中。 The string is always the same, with the only variation being the date and shift number: "My Information MM-DD-YY # Shift"
字符串始终相同,唯一的变化是日期和班次编号:“我的信息MM-DD-YY#班次”
I want to create code so that the user does not select new files each day, but the program checks for them via a comparison of the cells with the last date and shift ran to the date and shift within the file name in the folder. 我想创建代码,以使用户不必每天都选择新文件,但是程序会通过将单元格与上次日期进行比较来检查它们,然后将日期移动到文件夹中文件名之内。
Example: 例:
The user ran a file yesterday and it saved the date and shift into cells A1 and B1, 10-04-17 and 2, respectively. 用户昨天运行了一个文件,它保存了日期并将其转移到单元格A1和B1、10-04-17和2中。
The user forgot to run shift 3 yesterday. 该用户昨天忘记执行变速3。
They click the run button today, and the code looks at the directory (specified in the VBA) to see if there are any files where the date is equal to the date in cell A1 (10-04-17) and greater than the shift in cell B1 (2) as well as if there are any files greater than the date in shift A1 (10-04-17) with any shift number. 他们今天单击了运行按钮,并且代码查看了目录(在VBA中指定),以查看是否存在日期等于单元格A1(10-04-17)中的日期且大于shift的文件。单元格B1(2)中的文件,以及是否有大于班次A1(10-04-17)中日期的文件且带有任何班次编号。 Once it checks, it will select any of the files that meet this criteria and run the macro on them, saving the most recent date and shift to cells A1 and B1.
一旦检查,它将选择任何符合此条件的文件并在其上运行宏,保存最新日期并移至单元格A1和B1。
I already have multifile run functionality written into the existing program. 我已经将多文件运行功能写入现有程序。
Any help is appreciated! 任何帮助表示赞赏! Thank you in advance!
先感谢您!
For anyone who finds this and is curious, 对于任何发现并好奇的人,
I solved this in a bit of a roundabout way: 我以一种回旋的方式解决了这个问题:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.