0

This might be as rare as a ginger unicorn, however, is there a source-to-source (transcompiler) that compiles down to vba?

I've got some c# financial functions that would be great to reuse in vba.

j3r3m7
  • 742
  • 9
  • 21
  • 1
    [why don't you make a com visible library in C# and expose the functions to Vba?](http://vba4all.wordpress.com/category/c-and-vba/) –  Aug 04 '14 at 09:30
  • Hi, thanks for the comment. Portability and simplicity are the main reasons to not compile into a dll. I'd like to enable non technical excel and access users to simply copy and paste the code without the hassle of adding references. – j3r3m7 Aug 04 '14 at 09:52
  • hm.. it really depends on how much code we are talking about... obviously VBA is older than C# and it does not support some features that C# does so it may be really difficult to implement some things.... try [THIS FIRST](http://www.carlosag.net/Tools/CodeTranslator/) –  Aug 04 '14 at 10:09
  • I doubt it. There are program transformation engines that you could use to implement such a thing; see http://en.wikipedia.org/wiki/Program_transformation. While these make it possible, the process still isn't easy, and you will have a lot of trouble with library calls made by the C# code, since the libraries available are enormous. I suspect you are looking for a translator that is off the shelf already done. It might be less effort to hand-translate the code you have, unless that code itself is quite big. – Ira Baxter Aug 04 '14 at 11:21
  • Yeah, libraries referenced in the c# would be an issue. I was kind of hoping that there would be a typescript or coffeescript like transcompiler I could use. Interestingly the key things missing when having to manage vba code is the lack of decent unit testing and mocking frameworks(moq), modern source code management(git) and fully featured IDE(VS + Resharper). Wonder if I could get the typescript compiler to output vba ;-) – j3r3m7 Aug 04 '14 at 12:55

1 Answers1

0

So after much searching it appears there isn't a transcompiler available as of 06/Aug/2014.

It would appear that people either:

  • (a) code directly in vba and accept the limitations of the language and tooling

or

Community
  • 1
  • 1
j3r3m7
  • 742
  • 9
  • 21
  • In fact, the question of "does a transcompiler exist for A to B" for virtually any A and B is pretty much NO. First of all they are hard to build for specific A and B. Secondly there are lots and lots of combinations, especially when you take into account dialect variants of A and B. Third, such devices can almost never be "pure" because A never exists in a vacuum and its context has to be carried along too (for your example, C#, you have to handle the library calls, too, and the library is enormous). Such things tend to be built only on demand because the effort level is pretty high. – Ira Baxter Aug 06 '14 at 10:57
  • For transcompilers that do exist wikipedia has an article which shows the combinations available: http://en.wikipedia.org/wiki/Transcompiler I'm currently using both Typescript and Coffeescript which is why I thought, hey there must be one of these for vba. A particularly interesting one is Emscripten which was used to port the Unreal Engine to javascript! – j3r3m7 Aug 06 '14 at 11:11
  • I'm sure there are more than the Wikipedia page has, but it makes my point. – Ira Baxter Aug 06 '14 at 11:30