In MS Access I want to first check to see if Excel is open. If so, check to see if a certain workbook is already open. If not open it, otherwise set the open workbook as the active workbook.
Here is what I have so far. Almost there but if it is already open it gives a warning about re-opening an open workbook.
Private Function UpdateCrisisChart()Dim xls As ObjectDim wrk As ObjectDim Sheet As ObjectDim strExcelFile As String If IsExcelRunning Then Set xls = GetObject(, "Excel.Application") Else Set xls = CreateObject("Excel.Application") End If xls.Visible = True strExcelFile = GetExcelFilename(Me.SDate, "Adult") Set wrk = xls.Workbooks.Open(strExcelFile)End Function
The downside to Late Binding is that you lose the intellisense/autocompletion in programming, and possibly take a slight performance hit.
I typically keep both versions in my code and switch between them - commenting out the late binding in favor of early binding to get auto completion, and then switching back to late binding before deploying an application so that it will work regardless of Office version.
Set wrk = xls.Workbooks.Open(strExce