Hello, I am hoping that someone will be able to help me with a problem that I am having for my COM addin.
My Problem:
I would like to be able to call VBA's Format from my C# VSTO application, but this function is part of the VBA language and is not exposed via COM. Note that I am aware that .NET has a string.Format() function and that a similar function ExcelApp.WorksheetFunction.Text() exists that can be called via COM, but I would really like to be able to call the Format function in VBA since it takes different format strings than .NET's string.Format and has slightly different outputs than WorksheetFunction.Text.
Proposed Solution:
One way I could solve this is to call a VBA wrapper function that exists in a helper .xlam file from my C# code via Application.Run().
//VBA wrapper function in addin
//sample C# code
This works fine, but would require me to ship an xlam file along with my COM addin and I would also have to ensure that it was installed and deal with macro security for it to work. I would prefer to call the Format function directly without a wrapper, but I haven't had any luck doing that.
if you try this in the VBE intermediate window, you will get an error with this VBA code: ? Application.Run("Format", 1, "0.00")
Is there a fully qualified string that I can use for the Format function? I tried VBA.Strings.Format to no success.
Does anyone know of any other way I could access the Format function in a COM addin?
One thing I was looking at but havent had any success with are various apps that I found via Google that claim to be able to compile VBA functions into a DLL file which I was hoping I could reference into my VS project. However, I have not had any success getting my function converted to a dll file with any of these apps.
My Problem:
I would like to be able to call VBA's Format from my C# VSTO application, but this function is part of the VBA language and is not exposed via COM. Note that I am aware that .NET has a string.Format() function and that a similar function ExcelApp.WorksheetFunction.Text() exists that can be called via COM, but I would really like to be able to call the Format function in VBA since it takes different format strings than .NET's string.Format and has slightly different outputs than WorksheetFunction.Text.
Proposed Solution:
One way I could solve this is to call a VBA wrapper function that exists in a helper .xlam file from my C# code via Application.Run().
//VBA wrapper function in addin
Code:
Public Function VBAFormat(v As Variant, s As String) As String
VBAFormat = Format(v, s)
End Function
//sample C# code
Code:
string val = "2005/01/01";
string format = "[$-C0C]d mmm yyyy;@"; //A French Canadian locale specific format string
MessageBox.Show(Globals.ThisAddin.Application.Run("MyHelperAddin.VBAFormat", val, format));
This works fine, but would require me to ship an xlam file along with my COM addin and I would also have to ensure that it was installed and deal with macro security for it to work. I would prefer to call the Format function directly without a wrapper, but I haven't had any luck doing that.
if you try this in the VBE intermediate window, you will get an error with this VBA code: ? Application.Run("Format", 1, "0.00")
Is there a fully qualified string that I can use for the Format function? I tried VBA.Strings.Format to no success.
Does anyone know of any other way I could access the Format function in a COM addin?
One thing I was looking at but havent had any success with are various apps that I found via Google that claim to be able to compile VBA functions into a DLL file which I was hoping I could reference into my VS project. However, I have not had any success getting my function converted to a dll file with any of these apps.