2016-11-13 9 views
1

私はVBAスクリプト以下のように持っているクラスで、パブリック/プライベートサブの呼び出し中にエラーが定義されていませんa ClassVBAサブまたは関数が

私はbutton_clickサブルーチンを実行すると、エラーがスローされます。

Sub or function not defined

エラーがFindStringsCall ProcessFolder...ライン上で発生します。

私はエラーに関連する多くの問題を検索しましたサブまたは関数は定義されていませんまた、このエラーを修正するために提案された変更を実装しようとしましたが、動作しません。

このエラーの内容と解決方法については、ご了承ください。

+1

である必要があります。 –

+0

いいえ標準モジュール、ProcessFolder()、ProcessFile()をclassモジュールに入れたbutton_click()とFindStrings()は、誰かがエラーを解決するかもしれないと言われましたが、それらは4つの異なるモジュールにあります@TimWilliams – S6633d

+1

それらはすべて同じモジュールに入れて開始します –

答えて

0

あなたはModule内からClass内のメソッドを呼び出しているなら、あなたはインスタンス化Newキーワードでクラスにする必要があります。ドット表記のClassメソッドを参照してください。

一般的な例は次のようになります。

'Module 
Public Sub Foo() 
    Dim o As Class1 
    Set o = New Class1 
    o.Bar 
End Sub 

'Class1 
Public Sub Bar() 
    MsgBox "Hello world" 
End Sub 

あなたはどうしたらあなたの例するための手段はどの:あなたは新しいを作成する必要がFindStrings

  • 'Module 
    Sub button_click() 
    '< some code > 
        Call FindStrings (strfolder, Nothing) 
    End Sub 
    
    Public Sub FindStrings(strFolder As String, Optional wksSheet As Worksheet = Nothing) 
    ' < some code> 
        Dim o As YourClass 
        Set o = New YourClass 
        o.ProcessFolder(strFolder, strIndent, varStrings, varMatchesFound, varFileNames, lngFolderCount, lngFileCount) 
    
    End Sub 
    
    'YourClass 
    Public Sub ProcessFolder(strFolder As String, ByRef strIndent As String, ByRef varStrings As Variant, ByRef varMatchesFound As Variant, ByRef varFileNames As Variant, ByRef lngFolderCount As Long, lngFileCount As Long) 
    ' < some code> 
        Call ProcessFile(objFile.Path, strIndent, varStrings, varMatchesFound, varFileNames) 
    
    End Sub 
    
    Private Sub ProcessFile(strFullPath As String, ByRef strIndent As String, ByRef varStrings As Variant, ByRef varMatchesFound As Variant, ByRef varFileNames As Variant) 
    ' < some code> 
    End Sub 
    

    に留意されたいです。例:YourClass

  • YourClassProcessFolderサブルーチンはPublic
関連する問題