Can a VBA function return a workbook object?

I would like to call a function that will return a workbook object.  Is that possible?  If so how?
In the code below the last line above "ExitHere:" throws the following error.

Error #  91 was generated by VBAProject
Object variable or With block variable not set

Any help would be greatly appreciated.

Thanks,
Don
' This prompts the user for a File Name to open.
Function OpenWorkbook() As Workbook
 
On Error GoTo ErrHandler
    
    Dim Msg As String
    Dim vPath As Variant
    Dim wbTwo As Workbook
    
    vPath = Range("FilePath")
    
    If vPath = "" Then
        vPath = Application.GetOpenFilename()
        If vPath = False Then
            ' user cancelled, get out
            Exit Function
        End If
        Range("FilePath") = vPath
    End If
    
    Debug.Print "FileName: " & vPath
    Workbooks.Open Filename:=vPath
    
    Set wbTwo = ActiveWorkbook
    OpenWorkbook = wbTwo
    
ExitHere:
    Exit Function
    
ErrHandler:
If Err.Number <> 0 Then
    Msg = "Error # " & Str(Err.Number) & " was generated by " _
            & Err.Source & Chr(13) & Err.Description
    MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
End If
    
Resume ExitHere
End Function

Open in new window

dec789Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
I would do this:

    Debug.Print "FileName: " & vPath
    Set OpenWorkbook = Workbooks.Open( Filename:=vPath)
   
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dec789Author Commented:
Graham-Skan  Thank you very much that did the trick!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.