Not sure how the code create the instance of Word matters. I just need
something that identifies if Word is running, and if so, stops the macro. But
here is my code anyway:
Sub CommandCheck()
Dim oWord As Word.Application
Dim Counter As Boolean
Dim wdApp As Word.Application, wdDoc As Word.Document
Dim Dest As Workbook
Dim Source As Word.Document
Dim nextFile As Variant
Sheets("Sheet1").Select
Set RngColA = Range("A2", Range("A" & Rows.Count).End(xlUp))
Dim MyDir As String
MyDir = Workbooks("CommandCenter.xls").Path & "\"
Application.ScreenUpdating = False
Application.EnableEvents = False
NewFile = True
nextFile = Dir(MyDir & "*.doc")
Set wdApp = CreateObject("Word.Application")
'wdApp.Visible = True
For Each A In RngColA
If A <> "" Then
Do While nextFile <> ""
If (A & ".doc") = nextFile Then
Set wdDoc = wdApp.Documents.Open(MyDir & nextFile)
Range("C" & A.Row) =
wdApp.Documents(nextFile).Variables("TextBox1Text").Value
Range("C" & A.Row).Offset(1, 0) =
wdApp.Documents(nextFile).Variables("TextBox2Text").Value
Range("C" & A.Row).Offset(2, 0) =
wdApp.Documents(nextFile).Variables("TextBox3Text").Value
Range("C" & A.Row).Offset(3, 0) =
wdApp.Documents(nextFile).Variables("TextBox4Text").Value
Range("C" & A.Row).Offset(4, 0) =
wdApp.Documents(nextFile).Variables("TextBox5Text").Value
Range("C" & A.Row).Offset(5, 0) =
wdApp.Documents(nextFile).Variables("TextBox6Text").Value
Range("C" & A.Row).Offset(6, 0) =
wdApp.Documents(nextFile).Variables("TextBox7Text").Value
Range("C" & A.Row).Offset(7, 0) =
wdApp.Documents(nextFile).Variables("TextBox8Text").Value
Range("D" & A.Row) =
wdApp.Documents(nextFile).Variables("Green1BackColor").Value
Range("D" & A.Row).Offset(1, 0) =
wdApp.Documents(nextFile).Variables("Green2BackColor").Value
Range("D" & A.Row).Offset(2, 0) =
wdApp.Documents(nextFile).Variables("Green3BackColor").Value
Range("D" & A.Row).Offset(3, 0) =
wdApp.Documents(nextFile).Variables("Green4BackColor").Value
Range("D" & A.Row).Offset(4, 0) =
wdApp.Documents(nextFile).Variables("Green5BackColor").Value
Range("D" & A.Row).Offset(5, 0) =
wdApp.Documents(nextFile).Variables("Green6BackColor").Value
Range("D" & A.Row).Offset(6, 0) =
wdApp.Documents(nextFile).Variables("Green7BackColor").Value
Range("D" & A.Row).Offset(7, 0) =
wdApp.Documents(nextFile).Variables("Green8BackColor").Value
Range("E" & A.Row) =
wdApp.Documents(nextFile).Variables("Red1BackColor").Value
Range("E" & A.Row).Offset(1, 0) =
wdApp.Documents(nextFile).Variables("Red2BackColor").Value
Range("E" & A.Row).Offset(2, 0) =
wdApp.Documents(nextFile).Variables("Red3BackColor").Value
Range("E" & A.Row).Offset(3, 0) =
wdApp.Documents(nextFile).Variables("Red4BackColor").Value
Range("E" & A.Row).Offset(4, 0) =
wdApp.Documents(nextFile).Variables("Red5BackColor").Value
Range("E" & A.Row).Offset(5, 0) =
wdApp.Documents(nextFile).Variables("Red6BackColor").Value
Range("E" & A.Row).Offset(6, 0) =
wdApp.Documents(nextFile).Variables("Red7BackColor").Value
Range("E" & A.Row).Offset(7, 0) =
wdApp.Documents(nextFile).Variables("Red8BackColor").Value
Counter = True
End If
nextFile = Dir
Loop
If Counter = False Then
Range("C" & A.Row) = "File Missing"
Range("C" & A.Row).Offset(1, 0) = "File Missing"
Range("C" & A.Row).Offset(2, 0) = "File Missing"
Range("C" & A.Row).Offset(3, 0) = "File Missing"
Range("C" & A.Row).Offset(4, 0) = "File Missing"
Range("C" & A.Row).Offset(5, 0) = "File Missing"
Range("C" & A.Row).Offset(6, 0) = "File Missing"
Range("C" & A.Row).Offset(7, 0) = "File Missing"
Range("D" & A.Row) = "32768"
Range("D" & A.Row).Offset(1, 0) = "32768"
Range("D" & A.Row).Offset(2, 0) = "32768"
Range("D" & A.Row).Offset(3, 0) = "32768"
Range("D" & A.Row).Offset(4, 0) = "32768"
Range("D" & A.Row).Offset(5, 0) = "32768"
Range("D" & A.Row).Offset(6, 0) = "32768"
Range("E" & A.Row) = "128"
Range("E" & A.Row).Offset(1, 0) = "128"
Range("E" & A.Row).Offset(2, 0) = "128"
Range("E" & A.Row).Offset(3, 0) = "128"
Range("E" & A.Row).Offset(4, 0) = "128"
Range("E" & A.Row).Offset(5, 0) = "128"
Range("E" & A.Row).Offset(6, 0) = "128"
Range("E" & A.Row).Offset(7, 0) = "128"
End If
nextFile = Dir(MyDir & "*.doc")
Counter = False
End If
Next A
wdDoc.Close
wdApp.NormalTemplate.Save
wdApp.Quit
Sheets("Sheet1").Select
Columns("C:C").Select
Selection.TextToColumns Destination:=Range("C1"),
DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(64, 1)),
TrailingMinusNumbers:=True
Application.ScreenUpdating = True
MsgBox "Done"
End Sub