Creating a second word instance to run my project (Word 2000)

E

elle0612

Hello

I have one last obstacle to overcome with my project. At this stage it is
working more or less as i want it, application is hidden with only a userform
in view, and my labels are printing out fine, time after time of button
clicking, documents are opening and closing correctly etc etc.

My (final???) problem now is that when I close the applicatiion the way I
need to, ie Application.Close wdDoNotSaveChanges - so that its ready to be
used again another time, it also closes with it any documents that are laying
open at the bottom of the screen - this could well cause much anguish amongst
the users who (hopefully) will be using it in our office, and I'm sure to
become little miss unpopular!!

I think one option, if it can be done, would be to fire up the document in a
new instance of word, separate from the one that is already open with
documents at the bottom of the screen. Is this possible, and if so can
someone point me in the right direction of where to place the required code.
I have seen some code in a book that will open an instance of word from
another program - do I do this in the same way? And where should the start
up code be placed?

Thanks
 
J

Jean-Guy Marcil

elle0612 was telling us:
elle0612 nous racontait que :
Hello

I have one last obstacle to overcome with my project. At this stage
it is working more or less as i want it, application is hidden with
only a userform in view, and my labels are printing out fine, time
after time of button clicking, documents are opening and closing
correctly etc etc.

My (final???) problem now is that when I close the applicatiion the
way I need to, ie Application.Close wdDoNotSaveChanges - so that its
ready to be used again another time, it also closes with it any
documents that are laying open at the bottom of the screen - this
could well cause much anguish amongst the users who (hopefully) will
be using it in our office, and I'm sure to become little miss
unpopular!!

You bet!
I think one option, if it can be done, would be to fire up the
document in a new instance of word, separate from the one that is
already open with documents at the bottom of the screen. Is this
possible, and if so can someone point me in the right direction of
where to place the required code. I have seen some code in a book
that will open an instance of word from another program - do I do
this in the same way? And where should the start up code be placed?

I think the easiest is to check the Documents collection status when your
macro starts.

If Documents.Count = 1, then it is a safe bet that your document is the only
one running ion this instance of Word, so you can safely do Application.Quit
at the end.

If the count is higher than one, just close the current document (the one
containing the code).


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
E

elle0612

Thank you.

Where would be the best place to put this code?

In the macro editor screen?

Finding out where to put code such as this is the trickiest part. I know
that putting it in an event such as a button press is pointless here since
everything would have loaded by that stage and the only way to get out of the
userform is to press the Exit button since I have disabled the "X", so bye
bye all open files!!

The 'If documents.count >1' code would have to be run the minute after the
user starts up the document, perhaps I could issue a message box to say "save
your documents before using this application", and then hide the userform and
close the active document.

So please can you offer any advice on where to put the code for the best
results.

Thanks again
 
J

Jean-Guy Marcil

elle0612 was telling us:
elle0612 nous racontait que :
Thank you.

Where would be the best place to put this code?

In the macro editor screen?

Finding out where to put code such as this is the trickiest part. I
know that putting it in an event such as a button press is pointless
here since everything would have loaded by that stage and the only
way to get out of the userform is to press the Exit button since I
have disabled the "X", so bye bye all open files!!

The 'If documents.count >1' code would have to be run the minute
after the user starts up the document, perhaps I could issue a
message box to say "save your documents before using this
application", and then hide the userform and close the active
document.

So please can you offer any advice on where to put the code for the
best results.

First, you have to tell us how you instantiate the Userform. Where is the
code that creates/launches the userform?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
E

elle0612

Hello

this is all the code that affects the userform

Sub autonew()
'
' autonew Macro
' Macro created 15/08/2006

Application.Visible = False

UserForm1.Show

End Sub

---------------------------------

Private Sub UserForm_Activate()

tbxOne.SetFocus

End Sub

---------------------------------

Private Sub UserForm_QueryClose _
(Cancel As Integer, CloseMode As Integer)
'Prevents use of the 'X' button
If CloseMode = vbFormControlMenu Then
MsgBox "Please Use the Exit button"
Cancel = True
End If
End Sub
---------------------------------------------------
Private Sub btnExit_Click()
Application.Quit wdDoNotSaveChanges
End Sub

Thanks for your help.
 
E

elle0612

Hi

I think I've fixed it all. Like an idiot I wasn't making word visible again
after running all my code, therefore all the open documets at the bottom were
there, they were just invisible. That has now been fixed, what an idiot!!

So, if my document starts ok with no documents open, then the application is
hidden and exit button can be pressed (I've included application.visible at
the end just in case, but probably don't need it as the application closes.)

If there are documents already open, word becomes visible, a message box
appears to say "save and close all documents". When ok is pressed the open
documents appear for saving/closure. Then my application can be started up
again.

I put the code to count the documents in the userform_activate sub so now,
unless I'm mistaken and am missing something yet again (its very difficult to
discover problems until its used properly by other people I think) it seems
to work ok. Thanks very much for your advice and time. The only thing to
sort out now is my headache!!
 
J

Jean-Guy Marcil

elle0612 was telling us:
elle0612 nous racontait que :
Hi

I think I've fixed it all. Like an idiot I wasn't making word
visible again after running all my code, therefore all the open
documets at the bottom were there, they were just invisible. That has
now been fixed, what an idiot!!

So, if my document starts ok with no documents open, then the
application is hidden and exit button can be pressed (I've included
application.visible at the end just in case, but probably don't need
it as the application closes.)

If there are documents already open, word becomes visible, a message
box appears to say "save and close all documents". When ok is pressed
the open documents appear for saving/closure. Then my application
can be started up again.

I put the code to count the documents in the userform_activate sub so
now, unless I'm mistaken and am missing something yet again (its very
difficult to discover problems until its used properly by other
people I think) it seems to work ok. Thanks very much for your
advice and time. The only thing to sort out now is my headache!!

I would put all code not pertaining to the display of the userform oputside
the userform.
Something like:

Sub autonew()

Dim lngDocCount As Long
Dim myForm As UserForm1 'Or whatever name your userform has

lngDocCount = Documents.Count

Set myForm = New UserForm1
With myForm.Show

End Sub



--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jean-Guy Marcil

Jean-Guy Marcil was telling us:
Jean-Guy Marcil nous racontait que :

Arrgghh... I hate it when I do this!

Anybody knows how to disable CTRL-Enter as a shortcut to "Send Message" in
OE?

So, let me finish...

I would put all code not pertaining to the display of the userform
outside the userform.
Something like:

Sub autonew()

Dim lngDocCount As Long
Dim myForm As UserForm1 'Or whatever name your userform has

lngDocCount = Documents.Count

Set myForm = New UserForm1
With myForm
.Show
'Use UserForm content to interact with document
.Hide
End With

Unload myForm
Set myFrom = Nothing

If lngDocCount > 1 Then
ActiveDocument.Close wdDoNotSaveChganges
Else
Application.Quit wdDoNotSaveChganges
End if

End Sub

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
E

elle0612

Hi

Is that for good programming practice only, or because something will
eventually go wrong if you mix the two, ie userform display code and
non-userform display code. I presume then that the code not relating to the
userform would go in under the 'Module' object on the left hand panel of the
screen and not 'Form' object?

I put the count documents code under the userform_activate because I wanted
the documents to be checked the minute the userform appears.

Thanks
 
J

Jean-Guy Marcil

elle0612 was telling us:
elle0612 nous racontait que :
Hi

Is that for good programming practice only, or because something will
eventually go wrong if you mix the two, ie userform display code and
non-userform display code. I presume then that the code not relating
to the userform would go in under the 'Module' object on the left
hand panel of the screen and not 'Form' object?

Yes, it is good practice, and makes for code easier to managed/debug.
I put the count documents code under the userform_activate because I
wanted the documents to be checked the minute the userform appears.

That is the wrong place for this type of code.
Your userform has to be instantiated somewhere. (where is your code that
creates the userform, which module of which template holds the "AutoNew"
sub?)
The code that creates the userform is in a document that is currently
opened, right?
So, the code I provided will do the trick. You could count documents before
instantiating the userform and store that count in a variable. Then, after
unloading the form,use that variable to decide what to do next.

Of course, if the code is in a global template, the scenario might be
different, let us know if that is the case.


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top