Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Temporarily stop script


L.S.,

Within Excel I am running a script that opens a new Word-document.
I like to stop the script temporarily untill the Word-session is
closed.

Example:

Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.documents.Add

Msgbox ("Excel again")

The message should appear after closing the Word-session.

Possible?
With kind regards,
Hugo


--
H.A. de Wilde
------------------------------------------------------------------------
H.A. de Wilde's Profile: http://www.excelforum.com/member.php...o&userid=30679
View this thread: http://www.excelforum.com/showthread...hreadid=538800

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Temporarily stop script

Once word is opened and the document is added, the script moves on.

You could possibly have it loop and check for the existence of Word.

--
Regards,
Tom Ogilvy


"H.A. de Wilde" wrote:


L.S.,

Within Excel I am running a script that opens a new Word-document.
I like to stop the script temporarily untill the Word-session is
closed.

Example:

Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.documents.Add

Msgbox ("Excel again")

The message should appear after closing the Word-session.

Possible?
With kind regards,
Hugo


--
H.A. de Wilde
------------------------------------------------------------------------
H.A. de Wilde's Profile: http://www.excelforum.com/member.php...o&userid=30679
View this thread: http://www.excelforum.com/showthread...hreadid=538800


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Temporarily stop script


Dear Tom,

thank you for your reply.
Unfortunately I am not able to check for the existence of Word.
Which condition should I use to exit the loop?

With kind regards,
Hugo


--
H.A. de Wilde
------------------------------------------------------------------------
H.A. de Wilde's Profile: http://www.excelforum.com/member.php...o&userid=30679
View this thread: http://www.excelforum.com/showthread...hreadid=538800

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Temporarily stop script

Without testing

Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.documents.Add
Set objDoc = Nothing
do while objWord.Visible
loop
set objWord = Nothing
Msgbox ("Excel again")

--
Regards,
Tom Ogilvy


"H.A. de Wilde" wrote:


Dear Tom,

thank you for your reply.
Unfortunately I am not able to check for the existence of Word.
Which condition should I use to exit the loop?

With kind regards,
Hugo


--
H.A. de Wilde
------------------------------------------------------------------------
H.A. de Wilde's Profile: http://www.excelforum.com/member.php...o&userid=30679
View this thread: http://www.excelforum.com/showthread...hreadid=538800


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Temporarily stop script

Or, instead of using loops, why not use an event-based solution? Put the
below code in an Excel code module, call Initialize() and Terminate() as
appropriate, and you'll be able to listen to Application Quit and Document
Close events through the event handlers. I would strongly recommend the use
of event-based programming whereever and whenever possible, instead of
implementing tight loops to poll for state information, since the latter will
consume CPU cycles for virtually no good reason.

Cheers,
/MP

====================================

Option Explicit

Private WithEvents g_oApp As Word.Application
Private WithEvents g_oDoc As Word.Document

Private Sub Initialize()
Set g_oApp = CreateObject("Word.Application")
Set g_oDoc = g_oApp.Documents.Add

g_oApp.Visible = True
End Sub

Private Sub Terminate()
Set g_oDoc = Nothing
Set g_oApp = Nothing
End Sub

Private Sub g_oApp_Quit()
MsgBox "Word App Quit"
End Sub

Private Sub g_oDoc_Close()
MsgBox "Word Doc Close"
End Sub

==============================================


"Tom Ogilvy" wrote:

Without testing

Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.documents.Add
Set objDoc = Nothing
do while objWord.Visible
loop
set objWord = Nothing
Msgbox ("Excel again")

--
Regards,
Tom Ogilvy


"H.A. de Wilde" wrote:


Dear Tom,

thank you for your reply.
Unfortunately I am not able to check for the existence of Word.
Which condition should I use to exit the loop?

With kind regards,
Hugo


--
H.A. de Wilde
------------------------------------------------------------------------
H.A. de Wilde's Profile: http://www.excelforum.com/member.php...o&userid=30679
View this thread: http://www.excelforum.com/showthread...hreadid=538800




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Temporarily stop script


Dear Tom,

The loop works but is not working fine.
When the Word-document is minimized or there is a switch to anothe
application, the system does't perform good. Alos the return to Exce
is very slow. I think the loop is too risky. Sometimes an erro
occurs.


Dear Cheers,

Pasting the text:

Private WithEvents g_oApp As Word.Application
Private WithEvents g_oDoc As Word.Document

into a module, it turns into red.

Thanks for your replies.

Kind regards,
Hug

--
H.A. de Wild
-----------------------------------------------------------------------
H.A. de Wilde's Profile: http://www.excelforum.com/member.php...fo&userid=3067
View this thread: http://www.excelforum.com/showthread.php?threadid=53880

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Temporarily stop script

Hugo,
In a class module:
Dim WithEvents MyWord As Word.Application

Private Sub MyWord_Quit()
MsgBox "Excel again"
End Sub

Your original sub would need to end before then original MsgBox.
But you will then be notified when Word quits.

NickHK

"H.A. de Wilde"
wrote in message
news:H.A.de.Wilde.27a3bm_1146738301.6109@excelforu m-nospam.com...

L.S.,

Within Excel I am running a script that opens a new Word-document.
I like to stop the script temporarily untill the Word-session is
closed.

Example:

Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.documents.Add

Msgbox ("Excel again")

The message should appear after closing the Word-session.

Possible?
With kind regards,
Hugo


--
H.A. de Wilde
------------------------------------------------------------------------
H.A. de Wilde's Profile:

http://www.excelforum.com/member.php...o&userid=30679
View this thread: http://www.excelforum.com/showthread...hreadid=538800



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
Temporarily Unhiding [email protected] Excel Discussion (Misc queries) 1 September 29th 07 10:21 AM
Temporarily Disable Autocorrect Sloth Excel Discussion (Misc queries) 5 February 7th 07 04:24 PM
Temporarily turning off the keyboard? alfredo Excel Programming 4 February 13th 06 02:45 AM
Excel 2000/XP script to Excel97 script hat Excel Programming 3 March 2nd 04 03:56 PM
Temporarily delete ALL CommandBars? Kevin Excel Programming 3 August 26th 03 05:55 PM


All times are GMT +1. The time now is 07:15 AM.

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

About Us

"It's about Microsoft Excel"