Group:  Microsoft Word ยป microsoft.public.word.vba.addins
Thread: Word 2003 template running as "AddIn" - strange behaviour

Word 2003 template running as "AddIn" - strange behaviour
"Ian Bayly" <IanDBayly[ at ]GMail.com> 3/19/2007 2:26:24 AM
Hi
I'm posting in this forum because the problem is only evident when running
code from a button in a template loaded as an addin (or from start-up).
Code snip from a VBA Form button.
~~~~~~~
110 sFile = sRootPath & sDocType & "\" & Me.comboBranch & "\" &
Me.comboAnswer
'111 Me.Hide
112 Documents.Open fileName:=sFile
114 Documents(Me.comboAnswer).Activate
'116 Me.Show
~~~~~~
Line 112 gives me the error 5479, "You cannot close Microsoft Office Word
because you have a dialog box open......"
This only happens.
1. When Word has just been opened and has created a "Document1"
2. The Template is loaded as above.
It does NOT happen if:
1 I close Document1 and open a new document (Document2)
2. I close Document1
3. The code is run from the IDE
4. I rerun the code after getting the error.
5. I save Document1 as Document2
You may note that I have tried the Me.Hide/Show, and this corrects this
error, but it brings up other problems further down the code. Activate is
to get around the SDI display as I want the document behind the form.
I have a work around by trapping the error and rerunning the button code if
this error arises.

It sure is strange!

Has any one had anything like this and have a better fix?

TIA

Ian B


Re: Word 2003 template running as "AddIn" - strange behaviour
Cindy M. <C.Meister-C[ at ]hispeed.ch> 4/14/2007 10:15:58 AM
Hi Ian,

I can describe the reason you're seeing it. Start Word as a normal end user;
you'll see "Document 1". Now, before doing anything else (IOW don't "dirty"
the document) open a different document. You'll notice that Word closes the
default "new page" document, thus closing it. Apparently this triggers that
message, even though Word isn't actually closing (because Word now closes when
the last document is closed unless you explicitly use the File/Close command -
complicated).

If this were straight automation, I'd say start Word with the switch to
prevent a new document from being generated. But in this case, try just
setting the Saved property of this document = false so that Word thinks it's
"dirty" and see if that stops Word closing it.

[Quoted Text]
> I'm posting in this forum because the problem is only evident when running
> code from a button in a template loaded as an addin (or from start-up).
> Code snip from a VBA Form button.
> ~~~~~~~
> 110 sFile = sRootPath & sDocType & "\" & Me.comboBranch & "\" &
> Me.comboAnswer
> '111 Me.Hide
> 112 Documents.Open fileName:=sFile
> 114 Documents(Me.comboAnswer).Activate
> '116 Me.Show
> ~~~~~~
> Line 112 gives me the error 5479, "You cannot close Microsoft Office Word
> because you have a dialog box open......"
> This only happens.
> 1. When Word has just been opened and has created a "Document1"
> 2. The Template is loaded as above.
> It does NOT happen if:
> 1 I close Document1 and open a new document (Document2)
> 2. I close Document1
> 3. The code is run from the IDE
> 4. I rerun the code after getting the error.
> 5. I save Document1 as Document2
> You may note that I have tried the Me.Hide/Show, and this corrects this
> error, but it brings up other problems further down the code. Activate is
> to get around the SDI display as I want the document behind the form.
> I have a work around by trapping the error and rerunning the button code if
> this error arises.
>
> It sure is strange!
>
> Has any one had anything like this and have a better fix?
>

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)

Re: Word 2003 template running as "AddIn" - strange behaviour
"Ian B" <ian[ at ](TakeOut)docspro.co.nz> 4/18/2007 12:18:17 AM
Thanks for the explanation and solution Cindy
Strange it only started with Wd 2003!

Regards

Ian B

"Cindy M." <C.Meister-C[ at ]hispeed.ch> wrote in message
news:VA.00000c70.0080d514[ at ]speedy...
[Quoted Text]
> Hi Ian,
>
> I can describe the reason you're seeing it. Start Word as a normal end
user;
> you'll see "Document 1". Now, before doing anything else (IOW don't
"dirty"
> the document) open a different document. You'll notice that Word closes
the
> default "new page" document, thus closing it. Apparently this triggers
that
> message, even though Word isn't actually closing (because Word now closes
when
> the last document is closed unless you explicitly use the File/Close
command -
> complicated).
>
> If this were straight automation, I'd say start Word with the switch to
> prevent a new document from being generated. But in this case, try just
> setting the Saved property of this document = false so that Word thinks
it's
> "dirty" and see if that stops Word closing it.
>
> > I'm posting in this forum because the problem is only evident when
running
> > code from a button in a template loaded as an addin (or from start-up).
> > Code snip from a VBA Form button.
> > ~~~~~~~
> > 110 sFile = sRootPath & sDocType & "\" & Me.comboBranch & "\" &
> > Me.comboAnswer
> > '111 Me.Hide
> > 112 Documents.Open fileName:=sFile
> > 114 Documents(Me.comboAnswer).Activate
> > '116 Me.Show
> > ~~~~~~
> > Line 112 gives me the error 5479, "You cannot close Microsoft Office
Word
> > because you have a dialog box open......"
> > This only happens.
> > 1. When Word has just been opened and has created a "Document1"
> > 2. The Template is loaded as above.
> > It does NOT happen if:
> > 1 I close Document1 and open a new document (Document2)
> > 2. I close Document1
> > 3. The code is run from the IDE
> > 4. I rerun the code after getting the error.
> > 5. I save Document1 as Document2
> > You may note that I have tried the Me.Hide/Show, and this corrects this
> > error, but it brings up other problems further down the code. Activate
is
> > to get around the SDI display as I want the document behind the form.
> > I have a work around by trapping the error and rerunning the button code
if
> > this error arises.
> >
> > It sure is strange!
> >
> > Has any one had anything like this and have a better fix?
> >
>
> Cindy Meister
> INTER-Solutions, Switzerland
> http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
> http://www.word.mvps.org
>
> This reply is posted in the Newsgroup; please post any follow question or
> reply in the newsgroup and not by e-mail :-)
>


Re: Word 2003 template running as "AddIn" - strange behaviour
Cindy M. <C.Meister-C[ at ]hispeed.ch> 4/18/2007 4:27:25 PM
Hi Ian,

[Quoted Text]
> Strange it only started with Wd 2003!
>
MSFT keeps tweaking things, for various reasons. One could
well be trying to get the interaction with Outlook (Word as
email editor) to work more reliably.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:-)

Home | Search | Terms | Imprint
Newsgroups Reader