Reputation: 1020
I am going to execute C# dll through excel VBA . The file is macro enabled file(.xslm) I have to circulate this excel with several users. Is there a way embed an external dll with the excel file
Upvotes: 2
Views: 2221
Reputation: 333
There is a good way. (BTW, you could also embed a zip file and unzip file for user as a final step)
In the Ribbon. Insert -> Object-> Create from File
Now you have an embedded .dll within a worksheet. Next you need to extract the OLEObject file to your temp directory. This blog captures it well: https://danny.fyi/embedding-and-accessing-a-file-in-excel-with-vba-and-ole-objects-4d4e7863cfff
Next copy .dll from the temp to the directory you want to store the dll on the users machine. You'll see the GetOLETempPath() function in the blog.
Set obj = Sheets("Content").OLEObjects("stdCallObj")
filesource = GetOLETempPath(obj)
FileCopy filesource , "C:\somefolder\myNewDLL.dll"
Finally you load library
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
LoadLibrary("C:\somefolder\myNewDLL.dll")
Upvotes: 1
Reputation: 154
there is no good way (as far as I am aware) to accomplish this. apparently there are some way to hack it in, but it wont work on any protected systems (for good reasons). just zip the files together and distribute them together.
Upvotes: 1