Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Test if Word is running
I have a macro that cycles through a group of word docs and imports data into
an excel spreadsheet. Unfortunetly, if a copy of Word is running before the macro runs I get all kinds of errors. Is there any way to test from Excel if any copies of Word are running, and if so stop the macro? Using Excel 2003, thanks in advance! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Test if Word is running
How are you creating an instance of Word?
Post your code. -- Regards, Nigel "John" wrote in message ... I have a macro that cycles through a group of word docs and imports data into an excel spreadsheet. Unfortunetly, if a copy of Word is running before the macro runs I get all kinds of errors. Is there any way to test from Excel if any copies of Word are running, and if so stop the macro? Using Excel 2003, thanks in advance! |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Test if Word is running
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("Green1BackCol or").Value Range("D" & A.Row).Offset(1, 0) = wdApp.Documents(nextFile).Variables("Green2BackCol or").Value Range("D" & A.Row).Offset(2, 0) = wdApp.Documents(nextFile).Variables("Green3BackCol or").Value Range("D" & A.Row).Offset(3, 0) = wdApp.Documents(nextFile).Variables("Green4BackCol or").Value Range("D" & A.Row).Offset(4, 0) = wdApp.Documents(nextFile).Variables("Green5BackCol or").Value Range("D" & A.Row).Offset(5, 0) = wdApp.Documents(nextFile).Variables("Green6BackCol or").Value Range("D" & A.Row).Offset(6, 0) = wdApp.Documents(nextFile).Variables("Green7BackCol or").Value Range("D" & A.Row).Offset(7, 0) = wdApp.Documents(nextFile).Variables("Green8BackCol or").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 "Nigel" wrote: How are you creating an instance of Word? Post your code. -- Regards, Nigel "John" wrote in message ... I have a macro that cycles through a group of word docs and imports data into an excel spreadsheet. Unfortunetly, if a copy of Word is running before the macro runs I get all kinds of errors. Is there any way to test from Excel if any copies of Word are running, and if so stop the macro? Using Excel 2003, thanks in advance! |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Test if Word is running
Set the visible property of Word Application object to True .
If this post helps click Yes --------------- Jacob Skaria "John" wrote: I have a macro that cycles through a group of word docs and imports data into an excel spreadsheet. Unfortunetly, if a copy of Word is running before the macro runs I get all kinds of errors. Is there any way to test from Excel if any copies of Word are running, and if so stop the macro? Using Excel 2003, thanks in advance! |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Test if Word is running
Can you elaborate? How does setting the visible property allow me to test if
Word is running? "Jacob Skaria" wrote: Set the visible property of Word Application object to True . If this post helps click Yes --------------- Jacob Skaria "John" wrote: I have a macro that cycles through a group of word docs and imports data into an excel spreadsheet. Unfortunetly, if a copy of Word is running before the macro runs I get all kinds of errors. Is there any way to test from Excel if any copies of Word are running, and if so stop the macro? Using Excel 2003, thanks in advance! |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Test if Word is running
Nevermind...found a solution.
On Error Resume Next Set oWord = GetObject(, "Word.Application") If Err Then Else MsgBox ("Stop") End End If Credit goes to http://www.word.mvps.org/FAQs/InterD...XLFromWord.htm "Jacob Skaria" wrote: Set the visible property of Word Application object to True . If this post helps click Yes --------------- Jacob Skaria "John" wrote: I have a macro that cycles through a group of word docs and imports data into an excel spreadsheet. Unfortunetly, if a copy of Word is running before the macro runs I get all kinds of errors. Is there any way to test from Excel if any copies of Word are running, and if so stop the macro? Using Excel 2003, thanks in advance! |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Test if Word is running
Couple of suggestions...
Use Option Explicit as a single line at the top of the module. Qualify all objects with the appropriate parent object. (both Word and Excel have a range object)... Dim RngColA As Excel.Range Set MySht = ThisWorkbook.Sheets("Sheet1") Set RngColA = MySht.Range("A2", MySht.Range("A" & MySht.Rows.Count).End(xlUp)) ...all objects -- Jim Cone Portland, Oregon USA "John" wrote in message Nevermind...found a solution. On Error Resume Next Set oWord = GetObject(, "Word.Application") If Err Then Else MsgBox ("Stop") End End If Credit goes to http://www.word.mvps.org/FAQs/InterD...XLFromWord.htm |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Any way to test whether rows are empty or contain the word Pass ? | Excel Worksheet Functions | |||
Test for condition before running macro | Excel Programming | |||
How can I test in VBA what edition of Office a user is running | Excel Programming | |||
Combine Worksheets: Works Well in Test Mode, Locks when running no | Excel Programming | |||
Test if application running? | Excel Programming |