Click here to Skip to main content
15,868,014 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Working on an MS Access app.

I want to write some code and use it across a couple VBA apps...Access & Excel

In .Net you would just create another assembly and reference it.. How do you share code in Access/VBA?

Thanks

What I have tried:

Noting really as I have no clue what to look for. Spent a bunch of time on Google but didn't find anything relevant.
Posted
Updated 13-Apr-19 9:20am
Comments
Foothill 20-Jul-17 14:44pm    
Would this work:
https://aandreasen.wordpress.com/2008/05/05/how-to-create-a-dll-for-ms-excel-vba-with-microsoft-visual-c-2008-command-line-tools/

I believe that the closest thing to sharing code between applications (Access - Excel - Word - Powerpoint) would be to export the code module from one application and import it into the other application using the ide.

In the vba editor, in the Project view pane, right click the name of the module, select "Export File" from the pop up menu. Save it to a location easy to get to. It saves as a .bas file. In the other application, use the "Import" option.

This is awkward when you make changes as you have re-export and re-import the code module.
 
Share this answer
 
AFAIK, there is no such mechanism in VBA. The code is saved as part of the document, be it the database file or the .xl** workbook.

You can write your code as a COM-based .DLL in anything else you want, like C/C++, C#, VB.NET, VB6 (yuk!), register it on the machine and write VBA code against it using a COM reference.
 
Share this answer
 
Not sure if you must use VBA, but I have used ADOX and .NET to manipulate Access database as described in some of the articles found at adox c# - Google Search[^]. And Excel files using .NET and OleDB as described in Working with MS Excel(xls / xlsx) Using MDAC and Oledb[^].
 
Share this answer
 
I simply store my shared code in a separate .accdb file and add it as a reference. works great!
 
Share this answer
 
Hello Kevin
Are Online Please
I will contact you to ask question about GSM Modem code in C#
 
Share this answer
 
Comments
Member 14223135 13-Apr-19 15:37pm    
Yes, I am developing C# project which is USSD and I want to access Commands like money transfer and get company information
Can you help with any idea or source code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900