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.
' 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
Range("FilePath") = vPath
Debug.Print "FileName: " & vPath
Set wbTwo = ActiveWorkbook
OpenWorkbook = wbTwo
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