If you want to create an XLL (Excel Add-In) using C++ and the Excel SDK, but you still intend to call it from VBA, you can create a custom XLL function and then use VBA to call that function. Here’s a high-level overview of the steps:
-
Create an XLL Add-In:
- Write your C++ code using the Excel SDK to create a custom XLL function with the desired functionality (e.g., updating a range of cells).
- Build the C++ code into an XLL file.
-
Use VBA to Call the Custom XLL Function:
- In Excel, open the VBA editor (usually Alt + F11).
- In VBA, create a macro that calls the custom XLL function. You can use the
Application.Run method to call the XLL function.
Here’s an example of how you might call the custom XLL function from VBA:
Sub CallCustomXLLFunction()
' Call the custom XLL function using Application.Run
result = Application.Run("YourXLLFunctionName", arg1, arg2, ...) ' Replace with appropriate arguments
' 'result' contains the return value from the custom XLL function
' You can manipulate the result as needed in VBA
Replace "YourXLLFunctionName" with the name of your custom XLL function and provide the necessary arguments.
This approach allows you to create a custom XLL function using the Excel SDK and call it from VBA without the need to load it as a plugin or add-in in Excel. You can then use VBA to manage the data and interact with Excel as necessary.