What's wrong with this code?

F

Fred Goldman

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
 
T

Tony Jollans

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

Robert Paulsen

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

Fred Goldman

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

Fred Goldman

Helmut,

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top