Macro trouble

M

Mark

I've noticed the failure of several macros recently, they worked perfectly
for years under Word 2000 and have stopped with Word 2002. No idea why.

This is typical. It stops at rf.Path with Runtime error 5152: Method 'path'
of object 'RecentFile' failed. When in debug mode, 'Fullname' contains the
full file name/path of the first RecentFile so I don't see how rf.Path and
rf.Name have failed!
---
Sub CleanRecentFileList()
' Cleans history on file menu
' if file cannot be seen, it is removed from the list.

Dim rf As RecentFile, FullName As String
Const CLEARABSENTNETDOCS As Boolean = False
' Change to True to delete docs on absent network drives
Const CLEARABSENTREMOVABLES As Boolean = True
' Change to False to retain docs on absent removable drives
For Each rf In RecentFiles
FullName = rf.Path & Application.PathSeparator & rf.Name ' Fails here!

If FullName = Application.PathSeparator And CLEARABSENTNETDOCS Then
' Probably absent network drive
rf.Delete
Else
On Error Resume Next
' VBA raises error if file is on absent removable disk
If Dir(FullName) = "" Then
If (Err.Number <> 0 And CLEARABSENTREMOVABLES) Or (Err.Number = 0)
Then
rf.Delete
End If
Err.Clear
End If
On Error GoTo 0 ' Reinstate normal VBA error handling
End If
Next
End Sub
 
B

Bob Buckland ?:-\)

Hi Mark,

You may want to also post this in the Word VBA newsgroup
(link below)

========
I've noticed the failure of several macros recently, they worked perfectly
for years under Word 2000 and have stopped with Word 2002. No idea why.

This is typical. It stops at rf.Path with Runtime error 5152: Method 'path'
of object 'RecentFile' failed. When in debug mode, 'Fullname' contains the
full file name/path of the first RecentFile so I don't see how rf.Path and
rf.Name have failed!
---
Sub CleanRecentFileList()
' Cleans history on file menu
' if file cannot be seen, it is removed from the list.

Dim rf As RecentFile, FullName As String
Const CLEARABSENTNETDOCS As Boolean = False
' Change to True to delete docs on absent network drives
Const CLEARABSENTREMOVABLES As Boolean = True
' Change to False to retain docs on absent removable drives
For Each rf In RecentFiles
FullName = rf.Path & Application.PathSeparator & rf.Name ' Fails here!

If FullName = Application.PathSeparator And CLEARABSENTNETDOCS Then
' Probably absent network drive
rf.Delete
Else
On Error Resume Next
' VBA raises error if file is on absent removable disk
If Dir(FullName) = "" Then
If (Err.Number <> 0 And CLEARABSENTREMOVABLES) Or (Err.Number = 0)
Then
rf.Delete
End If
Err.Clear
End If
On Error GoTo 0 ' Reinstate normal VBA error handling
End If
Next
End Sub
---

Any ideas? Is it a missing reference?

Mark >>
--
LLet us know if this has helped you,

Bob Buckland ?:)
MS Office System Products MVP
*courtesy is not expensive and can pay big dividends8

A. Specific newsgroup/discussion group mentioned in this message:
news://msnews.microsoft.com/microsoft.public.word.vba.general

or via browser:
http://communities2.microsoft.com/communities/newsgroups/en-us/?dg=microsoft.public.word.vba.general

B. MS Office Community discussion/newsgroups via Web Browser
http://microsoft.com/office/community/en-us/default.mspx
or
Microsoft hosted newsgroups via Outlook Express/newsreader
news://msnews.microsoft.com
 

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