Doug,
I've been trying to use your code with a macro and userform as follows:
The basic macro:
Public Sub RecentFiles()
RecentFilesForm.Show
End
End Sub
******************************************
And the code in RecentFilesForm:
Private Sub UserForm_Initialize()
Application.ScreenUpdating = False
Dim RFArray() As Variant
Dim sourcedoc As Document, i As Integer, j As Integer, m As Long, myitem As
Range, n As Long
'********** Do something here to check for the existence of C:\Recent Files
List.doc
Set sourcedoc = Documents.Open(FileName:="C:\Recent Files List.doc")
' Get the number of rows in the table
i = sourcedoc.Tables(1).Rows.Count
'Define an array to be loaded with the client data
ReDim RFArray(i)
'Load client data into MyArray
For m = 0 To i - 1
Set myitem = sourcedoc.Tables(1).Cell(m + 1, n + 1).Range
myitem.End = myitem.End - 1
RFArray(m) = myitem.Text
Next m
' Load data into ListBox1
ListBox1.List() = RFArray
' Close the file containing the client details
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
End Sub
Private Sub CloseButton_Click()
End
End Sub
******************************************
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'Check to see if anything is selected
With ListBox1
If .ListIndex = -1 Then
MsgBox "Nothing is selected. You must make a selection, go back, or
cancel."
Else
RecentFilesForm.Hide
Documents.Open FileName:=ListBox1.Value
End
End If
End With
End Sub
******************************************
Private Sub OkayButton_Click()
'Check to see if anything is selected
With ListBox1
If .ListIndex = -1 Then
MsgBox "Nothing is selected. You must make a selection, go back, or
cancel."
Else
RecentFilesForm.Hide
Documents.Open FileName:=ListBox1.Value
End
End If
End With
End Sub
******************************************
The problem is, when I open word and click on RecentFiles before I do
anything else, I get error 91. If I then choose debug, it takes me to the
RecentFilesForm.Show line of the basic macro. If I then click on the Run
Macro error, it runs to the end, and will run perfectly well from then on
until I close Word again.
It only happens when the first thing I do after opening Word is trying to
run this macro. If I open a file first, it doesn't happen. I read the Help
on error 91 and tried a few things, but I'm just stumped.
Any idea why this is happening?
Best regards,
dsc