Question : Run-Time Error 5111 - This Command is not available on this platform

This was created in MS Word 2000, and known I am on MS Word 2007 and when running this code I get the error "Run-Time 5111 - This command is not available on this platform" Is there a way to fix this error?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
'This form uses a 3 page multipage control to imitate a wizard
 
'Page1 lists the type of studies and their associated document types
 
'Page2 gathers the information common for all documents generated
 
'Page3 is used to identify approvers for each document. This can be
 
'omitted or changed once the documents are created.
 
Option Explicit
Dim ListArray() As String
Dim str_DList As String
Dim str_AList As String
Dim str_Author As String
Dim str_DocType As String
Dim str_Path As String
Dim fs As Variant
Dim int_LcLen As Integer
Dim int_Len As Integer
Dim int_LCnt As Integer
Dim x As Integer
Dim i As Integer
Dim str_Location As String
 
 
Private Sub UserForm_Initialize()
 
    'avoid an error by setting focus to first page (index 0) of the multipage
    MultiPage1.Value = 0
    
    'get path to the source files
    str_Location = ActiveDocument.CustomDocumentProperties("Source Path").Value
    If Right(str_Location, 1) <> "\" Then str_Location = str_Location + "\"
    
    'set default approvers (to avoid an error when changing to page2 with no study selected
    str_AList = str_Location + "Default.csv"
    
    'populates the first list box with the study types the template supports
        Set fs = Application.FileSearch
        With fs
            .LookIn = str_Location
            .SearchSubFolders = False
            .FileName = "*.txt"
                If .Execute() > 0 Then
                    lstStudy.Visible = True
                        For i = 1 To .FoundFiles.Count
                            int_LcLen = Len(str_Location) + 1 ' may require and adjustment, not sure why
                            ' the list looks cleaner without path or extension
                            int_Len = Len(fs.FoundFiles(i)) - int_LcLen - 3
                            lstStudy.AddItem Mid(fs.FoundFiles(i), int_LcLen, int_Len)
                        Next i
                Else
                    MsgBox "The validation template source files could not be found." + vbNewLine _
                    + "Contact the  application owner for assistance."
                    Exit Sub
                End If
        End With
End Sub

Answer : Run-Time Error 5111 - This Command is not available on this platform

Sorry, but I don't have time to study all that code. What I'm suggesting you do is decompose the problem to its simplest pieces. You need to be sure that the Dir(pattern) approach can work. The test on the C:\temp\ directory produced no files. Fine. Now put 2 or 3 text files in c:\temp and run it again. It should list those file names in the immediate window. This is what I'm trying to get across: the Dir function is a very simple way to get what you need: a list of the files in a directory. That's what your original problem was -- the Application.FileSearch thing was simply supposed to retrieve a list of file names. You can do the same with Dir. But you are going to have to troubleshoot your own code.

One troubleshooting approach is to copy the troubling chunk of code into a separate macro and make sure it works there. Insert breakpoints and single step through the code using the Watch feature and examine every key variable at every step. Does something look wrong? Find out why the value is goofy. You have to single step so that you can see exactly what the state of the machine is when it throws the error. Usually one of the values in the erroring line of code has something wrong with it.
Random Solutions  
 
programming4us programming4us