CodexBloom - Programming Q&A Platform

VBA scenarios 'Object Variable or With Block Variable Not Set' When Using Late Binding with Excel Add-Ins

👀 Views: 82 đŸ’Ŧ Answers: 1 📅 Created: 2025-07-23
vba excel late-binding

I'm deploying to production and I've encountered a strange issue with I'm working with an scenario when trying to use late binding for an Excel add-in in my VBA code. The add-in is supposed to provide additional charting functionalities, but I keep getting the behavior message 'Object variable or With block variable not set' during runtime when I try to access a method from the add-in. I've tried initializing the object explicitly, but it doesn't seem to resolve the scenario. Here's the simplified version of my code: ```vba Dim chartAddIn As Object Set chartAddIn = Application.AddIns("MyChartAddIn.xlam") If Not chartAddIn Is Nothing And chartAddIn.Installed Then Dim chartObj As Object Set chartObj = Application.Workbooks(1).Charts.Add chartAddIn.SomeChartFunction chartObj Else MsgBox "Add-in is not installed or not found." End If ``` I have verified that the add-in is indeed installed and the name is correct. Running the code above leads to the mentioned behavior at the line `chartAddIn.SomeChartFunction chartObj`. Could this be due to an scenario with how the add-in is being referenced or initialized? Any insights on how to properly implement this using late binding and avoid the behavior would be greatly appreciated. I'm using Excel 2019. I'm working on a API that needs to handle this. I'm coming from a different tech stack and learning Vba. Am I approaching this the right way? I'd love to hear your thoughts on this.