What's wrong with this code?

What's wrong with this code?

Post by RnJlZCBHb2 » Fri, 17 Mar 2006 03:48:33


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
 
 
 

What's wrong with this code?

Post by Tony Jolla » Fri, 17 Mar 2006 04:08:28

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.



but
the

 
 
 

What's wrong with this code?

Post by RnJlZCBHb2 » Fri, 17 Mar 2006 04:20:31

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

What's wrong with this code?

Post by Helmut Web » Fri, 17 Mar 2006 05:28:21

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"
 
 
 

What's wrong with this code?

Post by Um9iZXJ0IF » Fri, 17 Mar 2006 05:32:26

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

What's wrong with this code?

Post by RnJlZCBHb2 » Fri, 17 Mar 2006 06:25:27

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

What's wrong with this code?

Post by RnJlZCBHb2 » Fri, 17 Mar 2006 06:27:28

Helmut,

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