Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 05-09-2022, 06:44 AM
grNadpa grNadpa is offline Design question: encapsulating excel workbook functions in word 2016 vba project Windows 10 Design question: encapsulating excel workbook functions in word 2016 vba project Office 2016
Advanced Beginner
Design question: encapsulating excel workbook functions in word 2016 vba project
 
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
 

Tags
excel 2016, vba code, word 2016



Similar Threads
Thread Thread Starter Forum Replies Last Post
Another Unique Question for managing a project plan in Excel IamThatGuy Excel 5 02-09-2022 02:10 PM
Excel 2016: A query from same workbook ArviLaanemets Excel 0 01-29-2018 07:22 AM
Macro Personal Workbook does not load in Excel 2016 Intruder Excel Programming 0 01-21-2017 05:44 AM
Design question: encapsulating excel workbook functions in word 2016 vba project Export Project in Excel Workbook codeghi Project 3 09-28-2016 11:32 AM
Newbie VBA question re Excel 2016 Highlander Excel Programming 3 01-22-2016 08:02 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:10 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft