Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default 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!
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default 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!

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default Test if Word is running

The solution is wholly dependent on how you create the instance of word, as
your later post and solution reveals.

--

Regards,
Nigel




"John" wrote in message
...
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!




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Any way to test whether rows are empty or contain the word Pass ? rCube Excel Worksheet Functions 1 December 22nd 09 04:48 PM
Test for condition before running macro Rookie 1st class Excel Programming 5 March 30th 09 03:53 PM
How can I test in VBA what edition of Office a user is running Hypernikao Excel Programming 5 June 5th 07 01:53 PM
Combine Worksheets: Works Well in Test Mode, Locks when running no BEEJAY Excel Programming 4 September 27th 06 08:46 PM
Test if application running? Chuck Excel Programming 1 December 7th 04 03:27 PM


All times are GMT +1. The time now is 06:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"