我试图找到一种方法来在每次保存某个文件夹中的文本文件,任何文本文件时运行宏。
有谁知道这样做的方法?
答案 0 :(得分:1)
Sub Monitor()
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceOperationEvent WITHIN 10 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name=""c:\\\\_Stuff""'")
Do While True
Set objEventObject = colMonitoredEvents.NextEvent()
Select Case objEventObject.Path_.Class
Case "__InstanceCreationEvent"
Debug.Print "A new file was just created: " & _
objEventObject.TargetInstance.PartComponent
Case "__InstanceDeletionEvent"
Debug.Print "A file was just deleted: " & _
objEventObject.TargetInstance.PartComponent
End Select
Loop
End Sub