LostInMD
Wed Oct 04 10:43:02 CDT 2006
Thanks for the quick reply Jean-Guy :)
In testing your suggestion, I create the environment that causes the quirk,
then:
In the immediate window I try -->
?Application.Documents.Count --> and get "1"
Then I try -->
?Application.ActiveDocument.Name --> and get "This command is not available
because no document is open."
Following are the steps and code that create my scenario. I start the Word
exe. I close the blank form that is loaded during the above step. I now
have a Word application with no open document (gray background). I then
click a command button with the following code behind it:
Application.KeyBindings.ClearAll()
Prior to my code hitting this line, in my immediate window I try -->
?Application.Documents.Count --> and get 0. Then I try -->
?Application.Windows.Count --> and get 0. Then I run the line of code
above. After the one line of above code is run, in my immediate window I try
-->
?Application.Documents.Count --> and get 1. Then I try -->
?Application.Windows.Count --> and get 0. Then I try -->
?Application.Documents(1).Name --> and get "Normal.dot".
Please let me know if the KeyBindings line of code creates the same results
for you in terms of the documents count. Thank you for all your help! Any
suggestions are greatly appreciated :)
"Jean-Guy Marcil" wrote:
> LostInMD was telling us:
> LostInMD nous racontait que :
>
> > Hi,
> >
> > I'm attempting to determine whether there is an ActiveDocument off the
> > Application.
> >
> > Scenario: Word application is running but there is no open document.
> > User clicks a commandbar button. I need to determine in the code
> > behind the button if there is an ActiveDocument for me to type text
> > onto. Cannot do a Application.Documents.Count b/c it sometimes
> > returns a hit for the Normal.dot template. I need to determine
> > whether there is an active .doc.
> >
> > Thanks!
>
> Use something like this:
>
> If Documents.Count > 0 Then
> MsgBox ActiveDocument.Name
> Else
> MsgBox "No documents opened."
> End If
>
> If you get a pop up stating "Normal.dot" than it means that your normal.dot
> is opened...
>
> I tried various things, and I never got the pop up to state "Normal.dot"
> unless it was actually opened.
>
> If you still get that weird result, show us your code.
>
> --
> Salut!
> _______________________________________
> Jean-Guy Marcil - Word MVP
> jmarcilREMOVE@CAPSsympatico.caTHISTOO
> Word MVP site:
http://www.word.mvps.org
>
>
>