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!

Re: Check if ActiveDocument Exists by Jean-Guy

Jean-Guy
Tue Oct 03 15:25:14 CDT 2006

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



Re: Check if ActiveDocument Exists by Steve

Steve
Tue Oct 03 16:16:16 CDT 2006

You could probably use the Tasks collection. Each task has both a 'Name'
property and a 'Visible' property. You could loop through the collection,
check if the right 14 characters in the string returned by the name property
were "Microsoft Word" and whenever you found such an instance, check if the
'Visible' property is true.

Steve


"LostInMD" <LostInMD@discussions.microsoft.com> wrote in message
news:C8B7E318-8E6D-4B40-9FC8-8B8F760D88E6@microsoft.com...
> 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!



Re: Check if ActiveDocument Exists by LostInMD

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
>
>
>

Re: Check if ActiveDocument Exists by LostInMD

LostInMD
Wed Oct 04 10:48:02 CDT 2006

Hi Steve,

Thank you very much for your suggestion. When I attempted to test your
method, I got a Tasks collection of 100+ items. I checked each item for the
name and found 2 "Microsoft Word" and both had the 'Visible' property = true.
(All the while the Documents.Count = 1 and the Windows.Count = 0). If you
don't mind, please try the scenario in my reply to Jean-Guy Marcil (located
right above your reply) and return feedback. Any assistance would be greatly
appreciated!

Thanks!

"Steve Yandl" wrote:

> You could probably use the Tasks collection. Each task has both a 'Name'
> property and a 'Visible' property. You could loop through the collection,
> check if the right 14 characters in the string returned by the name property
> were "Microsoft Word" and whenever you found such an instance, check if the
> 'Visible' property is true.
>
> Steve
>
>
> "LostInMD" <LostInMD@discussions.microsoft.com> wrote in message
> news:C8B7E318-8E6D-4B40-9FC8-8B8F760D88E6@microsoft.com...
> > 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!
>
>
>

Re: Check if ActiveDocument Exists by Jean-Guy

Jean-Guy
Wed Oct 04 17:23:17 CDT 2006

LostInMD was telling us:
LostInMD nous racontait que :

> 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 :)

I cannot reproduce.

Documents.Count is always 0, even after creating a button in my Normal.dot
that would call the keybinding code and following you scenario.

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