If Bob.doc is open the code runs fine even when I open a different doc, but
if it's not open the code has a fit at line 6 even if Bob.doc exists on the
harddrive. Any suggestions?


Application.Keyboard (1037)
If ActiveDocument.Bookmarks.Exists("Here") Then
Selection.GoTo What:=wdGoToBookmark, Name:="Here"
Else: Selection.EndKey Unit:=wdStory
End If
If ActiveDocument = Documents("C:\Word Documents\Bob.doc"). Then
Application.TaskPanes(wdTaskPaneFormatting).Visible = True
End If

Re: What's wrong with this code? by Tony

Tony
Wed Mar 15 13:08:28 CST 2006

Documents("C:\Word Documents\Bob.doc") is trying to refer to an open
document. If there isn't an *open* document with that name and path Word
won't find one - nothing more than that. Word does not go checking your hard
drive - the documents collection explicitly includes open documents only.

--
Enjoy,
Tony

"Fred Goldman" <FredGoldman@discussions.microsoft.com> wrote in message
news:1D5A8300-2FDD-47B2-8435-3C395347A23E@microsoft.com...
> If Bob.doc is open the code runs fine even when I open a different doc,
but
> if it's not open the code has a fit at line 6 even if Bob.doc exists on
the
> harddrive. Any suggestions?
>
>
> Application.Keyboard (1037)
> If ActiveDocument.Bookmarks.Exists("Here") Then
> Selection.GoTo What:=wdGoToBookmark, Name:="Here"
> Else: Selection.EndKey Unit:=wdStory
> End If
> If ActiveDocument = Documents("C:\Word Documents\Bob.doc"). Then
> Application.TaskPanes(wdTaskPaneFormatting).Visible = True
> End If



Re: What's wrong with this code? by FredGoldman

FredGoldman
Wed Mar 15 13:20:31 CST 2006

Thanks Tony, so how would I say If ActiveDocument is blank then do this?

"Tony Jollans" wrote:

> Documents("C:\Word Documents\Bob.doc") is trying to refer to an open
> document. If there isn't an *open* document with that name and path Word
> won't find one - nothing more than that. Word does not go checking your hard
> drive - the documents collection explicitly includes open documents only.
>
> --
> Enjoy,
> Tony
>
> "Fred Goldman" <FredGoldman@discussions.microsoft.com> wrote in message
> news:1D5A8300-2FDD-47B2-8435-3C395347A23E@microsoft.com...
> > If Bob.doc is open the code runs fine even when I open a different doc,
> but
> > if it's not open the code has a fit at line 6 even if Bob.doc exists on
> the
> > harddrive. Any suggestions?
> >
> >
> > Application.Keyboard (1037)
> > If ActiveDocument.Bookmarks.Exists("Here") Then
> > Selection.GoTo What:=wdGoToBookmark, Name:="Here"
> > Else: Selection.EndKey Unit:=wdStory
> > End If
> > If ActiveDocument = Documents("C:\Word Documents\Bob.doc"). Then
> > Application.TaskPanes(wdTaskPaneFormatting).Visible = True
> > End If
>
>
>

Re: What's wrong with this code? by Helmut

Helmut
Wed Mar 15 14:28:21 CST 2006

Hi Fred,

one could check if there is a document with that name open.

Untestet:

dim oDcm as document
for each odcm in documents
if odcm.fullname = "c:\....doc" then
endif
next

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Re: What's wrong with this code? by RobertPaulsen

RobertPaulsen
Wed Mar 15 14:32:26 CST 2006

Instead of:
If ActiveDocument = Documents("C:\Word Documents\Bob.doc"). Then
try
If LCase$(ActiveDocument.Fullname) = "c:\word documents\bob.doc" Then


"Fred Goldman" wrote:

> Thanks Tony, so how would I say If ActiveDocument is blank then do this?
>
> "Tony Jollans" wrote:
>
> > Documents("C:\Word Documents\Bob.doc") is trying to refer to an open
> > document. If there isn't an *open* document with that name and path Word
> > won't find one - nothing more than that. Word does not go checking your hard
> > drive - the documents collection explicitly includes open documents only.
> >
> > --
> > Enjoy,
> > Tony
> >
> > "Fred Goldman" <FredGoldman@discussions.microsoft.com> wrote in message
> > news:1D5A8300-2FDD-47B2-8435-3C395347A23E@microsoft.com...
> > > If Bob.doc is open the code runs fine even when I open a different doc,
> > but
> > > if it's not open the code has a fit at line 6 even if Bob.doc exists on
> > the
> > > harddrive. Any suggestions?
> > >
> > >
> > > Application.Keyboard (1037)
> > > If ActiveDocument.Bookmarks.Exists("Here") Then
> > > Selection.GoTo What:=wdGoToBookmark, Name:="Here"
> > > Else: Selection.EndKey Unit:=wdStory
> > > End If
> > > If ActiveDocument = Documents("C:\Word Documents\Bob.doc"). Then
> > > Application.TaskPanes(wdTaskPaneFormatting).Visible = True
> > > End If
> >
> >
> >

Re: What's wrong with this code? by FredGoldman

FredGoldman
Wed Mar 15 15:25:27 CST 2006

Thanks Robert,
The Lcase thing didn't work, but the fullname property was exactly what I
needed.

"Robert Paulsen" wrote:

> Instead of:
> If ActiveDocument = Documents("C:\Word Documents\Bob.doc"). Then
> try
> If LCase$(ActiveDocument.Fullname) = "c:\word documents\bob.doc" Then
>
>
> "Fred Goldman" wrote:
>
> > Thanks Tony, so how would I say If ActiveDocument is blank then do this?
> >
> > "Tony Jollans" wrote:
> >
> > > Documents("C:\Word Documents\Bob.doc") is trying to refer to an open
> > > document. If there isn't an *open* document with that name and path Word
> > > won't find one - nothing more than that. Word does not go checking your hard
> > > drive - the documents collection explicitly includes open documents only.
> > >
> > > --
> > > Enjoy,
> > > Tony
> > >
> > > "Fred Goldman" <FredGoldman@discussions.microsoft.com> wrote in message
> > > news:1D5A8300-2FDD-47B2-8435-3C395347A23E@microsoft.com...
> > > > If Bob.doc is open the code runs fine even when I open a different doc,
> > > but
> > > > if it's not open the code has a fit at line 6 even if Bob.doc exists on
> > > the
> > > > harddrive. Any suggestions?
> > > >
> > > >
> > > > Application.Keyboard (1037)
> > > > If ActiveDocument.Bookmarks.Exists("Here") Then
> > > > Selection.GoTo What:=wdGoToBookmark, Name:="Here"
> > > > Else: Selection.EndKey Unit:=wdStory
> > > > End If
> > > > If ActiveDocument = Documents("C:\Word Documents\Bob.doc"). Then
> > > > Application.TaskPanes(wdTaskPaneFormatting).Visible = True
> > > > End If
> > >
> > >
> > >

Re: What's wrong with this code? by FredGoldman

FredGoldman
Wed Mar 15 15:27:28 CST 2006

Helmut,

It's a AutoOpen macro so I don't know if this would work, but I got it
worked out anyway, thanks!

"Helmut Weber" wrote:

> Hi Fred,
>
> one could check if there is a document with that name open.
>
> Untestet:
>
> dim oDcm as document
> for each odcm in documents
> if odcm.fullname = "c:\....doc" then
> endif
> next
>
> --
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP WordVBA
>
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
>