elle0612 was telling us:
elle0612 nous racontait que :
> Hello
>
[quoted text clipped - 11 lines]
> 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
[quoted text clipped - 3 lines]
> 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).

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
elle0612 - 31 Aug 2006 20:33 GMT
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
> elle0612 was telling us:
> elle0612 nous racontait que :
[quoted text clipped - 34 lines]
> If the count is higher than one, just close the current document (the one
> containing the code).
Jean-Guy Marcil - 31 Aug 2006 23:00 GMT
elle0612 was telling us:
elle0612 nous racontait que :
> Thank you.
>
[quoted text clipped - 16 lines]
> 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?

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
elle0612 - 01 Sep 2006 10:17 GMT
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.
> elle0612 was telling us:
> elle0612 nous racontait que :
[quoted text clipped - 22 lines]
> First, you have to tell us how you instantiate the Userform. Where is the
> code that creates/launches the userform?
elle0612 - 01 Sep 2006 11:50 GMT
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!!
> Hello
>
[quoted text clipped - 62 lines]
> > First, you have to tell us how you instantiate the Userform. Where is the
> > code that creates/launches the userform?
Jean-Guy Marcil - 01 Sep 2006 14:26 GMT
elle0612 was telling us:
elle0612 nous racontait que :
> Hi
>
[quoted text clipped - 18 lines]
> 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

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Jean-Guy Marcil - 01 Sep 2006 14:37 GMT
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

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
elle0612 - 02 Sep 2006 11:54 GMT
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
> Jean-Guy Marcil was telling us:
> Jean-Guy Marcil nous racontait que :
[quoted text clipped - 34 lines]
>
> End Sub
Jean-Guy Marcil - 02 Sep 2006 18:23 GMT
elle0612 was telling us:
elle0612 nous racontait que :
> Hi
>
[quoted text clipped - 3 lines]
> 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.

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org