events - How do I know when a file has been modified in a VBA Macro? -
Is there a way to view the file in VBA (which is essentially VB6), so that I know the file When has it been modified? - Only when I do not want to know about its modified , a file is unused .
I have recommended using the "FileSystemWorld" and the Win32 API "FindFirstChangeNotification". I can not understand how to use them, however, any thoughts?
OK, I work together to find out which file system changes in VBA (VB6) Enabled. The public objWMIService, colmonitoredEvents, objEventObject 'every 1 second call for changes' sub clock (error) timed out on GoTo if objWMIService is nothing then once again initWatch 'Once init' right Set the objEventObject = colmonitoredEvents.NextEvent (1) '1 msec timeout if no events' messagebox' event found "Select episode objEventObject.Path_.Class case" __InstanceCreationEvent "MsgBox" A new file was just created: "& Amp; _ ObjEventObject.TargetInstance.PartComponent case "__InstanceDeletionEvent" MsgBox "A file was deleted now:" & amp; ; _ ObjEventObject.TargetInstance.PartComponent case "__InstanceModificationEvent" MsgBox "A file was just modified:" & ObjEventObject.TargetInstance.PartComponent End Select loop exit sub timeout: if trim (error source) = "SWbemEventSource" And trim (error description) = "Time has expired" then MsgBox "There are no events in the last 1 second" Other message "If you copy and paste this sub near above, it is called automatically, If necessary to start Global Wars .
sub
InitWatch () Error GoTo initerr Dim as the integer on watchSecs, watchpath string as watchchek = 1 'watchpath =' c: \\\ "Seconds" behind the \ 'scripts \' "StComputer =" to see the changes in this DIR. " ObjWMIService = GetObject (set "winmgmts: \\" & amp; strComputer & amp; "\ root \ cimv2") Set ColMonitoredEvents = objWMIService.ExecNotificationQuery_ ("SELECT * FROM __InstanceOperationEvent within" & amp; clockCAC and "WHERE "_ & Amp; Targetinstance ISA 'CIM_DirectoryContainsFile' and" _ & amp; "TargetInstance.GroupComponent =" _ & "Win32_Directory.Name =" "c: \\\\ Script" "') MsgBox" init done "out Exit sub initerr: MsgBox "Error during Init -" & amp; Err.Source & amp; "-" & amp; Err.Description End sub
Comments
Post a Comment