View Single Post
 
Old 05-09-2022, 06:44 AM
grNadpa grNadpa is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Mar 2022
Posts: 46
grNadpa is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post

In any event, you should avoid using 'On Error' wherever possible, as doing so might be hiding errors you shouldn't be ignoring.
In lieu of "On Error", I'd welcome your alternative should the "Set" of the workbook below fail.
Code:
Function InstantiateWorkbook() As Boolean
'Purpose:   Instantiate session's Excel Workbook
'Requires:  RosterPath (Windows Explorer path to workbook)
'Returns:   exwb (Excel Workbook)
'           objExcel (Excel.Application)
'Note:      RosterPath, exwb and objExcel defined in Declarations
    On Error GoTo InstantiateError
    
    Set exwb = objExcel.Workbooks.Open(RosterPath)
    
    On Error Resume Next
    InstantiateWorkbook = True
    Exit Function
    
InstantiateError:
    MsgBox "Error initializing Roster Spreadsheet." & vbCrLf & _
        "Have programmer confirm that" & vbCrLf & _
        "(1) MicrosoftExcel 16.0 Object Library" & vbCrLf & _
        vbTab & "checked in Project References" & vbCrLf & _
        "(2) " & RosterPath & vbCrLf & _
            "folder is present", , "Activation Error"

    UnlockSpreadsheet
    InstantiateWorkbook = False
    Exit Function
Code:
Sub UnlockSpreadsheet()
    On Error Resume Next
    exwb.Close
    Set exwb = Nothing
End Sub
Reply With Quote