Topic: Calling some vba

Hi Steve,
This is a bit of a big ask, but if you can shed any light on it, it would be greatly appreciated. I have a pretty big piece of VBA code that I wrote in an excel sheet and I'm looking for a way to call it from FORTRAN. If I knew how, (and it was easy) I'd make a DLL and try and somehow call it from Fortran. Do you know of any way that can be done? My first attempt was to feed it into chat GPT which did a great job of translating the VB to Fortran inasmuch as it compiles without error. Sadly, the answers that I get are wildly incorrect and short of a marathon debugging session, I probably won't get it to work satisfactorily. Any help/discussion would be greatly appreciated.

Re: Calling some vba

Peter,
I suggest that you search the Approximatrix Forums using the key words: VBA DLL
There have been several discussion on this topic.

Re: Calling some vba

Hi DrFrank,
What I wanted to do was the opposite of the forum posts. They are all about VB calling a fortran DLL. I want to create a VB DLL and call it from fortran.

Re: Calling some vba

Peter,

I have no idea how to create an EXCEL DLL from VBA code. If your EXCEL VBA code is raw number crunching and doesn't include calls to EXCEL graphics and spreadsheet functions, I suggest converting it to FORTRAN code since you want to call it from FORTRAN anyway. Sorry I don't have a more direct solution to your problem.

Re: Calling some vba

Calling VB from Fortran is certainly possible, but it won't be straightforward at all.  First, unless you're planning to use Visual Basic 6, you need to build an "unmanaged" DLL, meaning it is not running within the .NET CLR.  To the best of my knowledge, building a VB.NET DLL that is unmanaged is not possible.

So, you'd have to create some sort of shim to forward native calls to a .NET DLL, which is going to be pretty painful.  I don't really have a good example to start from since I've never seen this request before.  There are some pertinent questions on StackOverflow that start to explain how exceedingly complex this task is going to get.

Jeff Armstrong
Approximatrix, LLC

Re: Calling some vba

Thanks DrFrank and Jeff!
At the end of the day, I decided to do the code conversion from VBA to Fortran myself - I was too afraid of getting stuck way down in the weeds in building the DLL and testing it. Syntactically, it isn't difficult, just a tad tedious. Thank you both for your comments and ideas.
Regards,
Pete

Re: Calling some vba

Peter,
You can try translating your VBA code into FreeBasic (https://github.com/PaulSquires/WinFBE/releases). It shouldn't be so tedious because FBA is also a dialect of Basic. Then creating a DLL is easy (if I remember correctly).
Carlos