如何将我的Sub变成一个函数?

时间:2015-04-14 07:42:42

标签: vb.net visual-studio function

Option Explicit
Private objFSO As New FileSystemObject

Sub GetDirectory()

Dim WorkbookDir As String


    WorkbookDir = ThisWorkbook.Path


    ' Check wether file exists



        ' Assume that the file does not exist and is not writeable to begin with
    Dim fileIsGood As Boolean
    Dim fileObject As Object

    ' Look for the log file path and make sure that it exists
    If objFSO.FileExists(WorkbookDir) Then

        WorkbookDir = True

    End If


End Sub

1 个答案:

答案 0 :(得分:0)

Option Explicit
Private objFSO As New FileSystemObject

Function GetDirectory() as Boolean

Dim WorkbookDir As String


WorkbookDir = ThisWorkbook.Path


' Check wether file exists



    ' Assume that the file does not exist and is not writeable to begin with
Dim fileIsGood As Boolean
Dim fileObject As Object

' Look for the log file path and make sure that it exists
If objFSO.FileExists(WorkbookDir) Then

    WorkbookDir = True

End If

return WorkBookDir

End Function