Attribute VB_Name = "main" Dim pApp As esriFramework.IApplication Dim pDoc As esriFramework.IDocument Dim esriAppRef As esriFramework.AppRef Dim v As esriFramework.IVbaApplication Private Sub allMXDs() Dim rootFolder As String ' ' alter this rootFolder to search in a different area ' Let rootFolder = "G:\" ' Dim fss As FileSystemScanner Set fss = New FileSystemScanner Call fss.ScanFor(rootFolder, ".mxd") End Sub Sub batch() Dim b As FileBatcher Set b = New FileBatcher Call b.applyMacro("processMXD") End Sub Private Function processMXD(fPath As String, fDestName As String) Set pDoc = CreateObject("esriArcMapUI.MxDocument") Set pApp = pDoc.Parent Set esriAppRef = pApp ' I think this does a QI esriAppRef.Visible = True On Error GoTo errorHandler ' want to do a Application.OLEServerBusyRaiseError = True Application.DisplayAlerts = False esriAppRef.OpenDocument (fPath) ' wait until the actual document is in the window Application.Wait Now + TimeValue("00:01:00") ' Debug.Print ("Calling macro, saving manifest to " & fDestName) ' this is the final resting place - probably should move this setting away... fDestName = "G:\filecopy\new_manifests\" & fDestName Dim myParams myParams = Array(fPath, fDestName) Set pDoc = esriAppRef.Document Set v = esriAppRef Call v.RunVBAMacro("Normal", "sapphos", "processThisMXD", myParams) Call esriAppRef.Shutdown errorHandler: If (Err = 0) Then Debug.Print "Worked" processMXD = "Processed" ElseIf (Err = 18) Then processMXD = "Interrupted" Debug.Print "Interrupt" Stop Else Debug.Print "Error " & Err & ", recording error and continuing." processMXD = "Error" KillArcMap End If End Function Sub KillArcMap() CloseAPP "ArcMap.exe", True, False End Sub '************************************** Sub KillTest_B() CloseAPP_B "notepad.exe" End Sub '************************************** 'Close Application 'CloseApp KillAll=False -Only first occurrence ' KillAll=True -All occurrences ' NeedYesNo=True -Prompt to kill ' NeedYesNo=False -Silent kill Private Function CloseAPP(AppNameOfExe As String, Optional KillAll As Boolean = False, _ Optional NeedYesNo As Boolean = True) As Boolean Dim oProcList As Object Dim oWMI As Object Dim oProc As Object CloseAPP = False ' step 1: create WMI object instance: Set oWMI = GetObject("winmgmts:") If IsNull(oWMI) = False Then ' step 2: create object collection of Win32 processes: Set oProcList = oWMI.InstancesOf("win32_process") ' step 3: iterate through the enumerated collection: For Each oProc In oProcList 'MsgBox oProc.Name ' option to close a process: If UCase(oProc.Name) = UCase(AppNameOfExe) Then If NeedYesNo Then If MsgBox("Kill " & oProc.Name & vbNewLine & "Are you sure?", _ vbYesNo + vbCritical) = vbYes Then oProc.Terminate (0) 'no test to see if this is really true CloseAPP = True End If 'MsgBox("Kill " Else 'NeedYesNo oProc.Terminate (0) 'no test to see if this is really true CloseAPP = True End If 'NeedYesNo 'continue search for more??? If Not KillAll And CloseAPP Then Exit For 'oProc In oProcList End If 'Not KillAll And CloseAPP End If 'IsNull(oWMI) = False Next 'oProc In oProcList Else 'IsNull(oWMI) = False 'report error End If 'IsNull(oWMI) = False ' step 4: close log file; clear out the objects: Set oProcList = Nothing Set oWMI = Nothing End Function '************************************** 'No frills killer Private Function CloseAPP_B(AppNameOfExe As String) Dim oProcList As Object Dim oWMI As Object Dim oProc As Object ' step 1: create WMI object instance: Set oWMI = GetObject("winmgmts:") If IsNull(oWMI) = False Then ' step 2: create object collection of Win32 processes: Set oProcList = oWMI.InstancesOf("win32_process") ' step 3: iterate through the enumerated collection: For Each oProc In oProcList ' option to close a process: If UCase(oProc.Name) = UCase(AppNameOfExe) Then oProc.Terminate (0) End If 'IsNull(oWMI) = False Next 'oProc In oProcList Else 'IsNull(oWMI) = False 'report error End If 'IsNull(oWMI) = False ' step 4: close log file; clear out the objects: Set oProcList = Nothing Set oWMI = Nothing End Function '**************************************