The windows script host seems to think this was OK because instead of a bunch of error messages, I got a " begin monitoring for folder changes" message. However, nothing happens when I make a change to the folder (ie paste in a file). I have an extremely simple macro that I am trying to test fire when I paste a file into "C:\Receive." Any suggestions?
PS I left in the Select case with a single case because I cannot seem to make an If statement work in this.
PS I left in the Select case with a single case because I cannot seem to make an If statement work in this.
Code:
Dim xlApp
Set xlApp = CreateObject("Excel.Application")
strComputer = "."
strDirToMonitor = "C:\\\\Receive"
strTime = "10"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceOperationEvent WITHIN " & strTime & " WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name=" & Chr(34) & strDirToMonitor & Chr(34) & "'")
Wscript.Echo vbCrlf & Now & vbTab & _
"Begin Monitoring for a Folder Change Event..." & vbCrlf
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
Select Case objLatestEvent.Path_.Class
Case" _instanceCreationEvent "
With xlApp
.Workbooks.Activate ("C:\GetTest")
.Application.Run "GetTest.xls!Button2_Click"
.Application.Quit
End With
End Select
Loop
Set objWMIService = nothing
Set colMonitoredEvents = nothing
Set objLatestEvent = nothing