I'm using .NET library exposed to COM from VBA. The library interface uses the TimeSpan
class for settable property. Is there any way I can construct the TimeSpan
via COM, so that I can assign a value to the property?
I found I can instantiate some System
assembly types, if I register the assembly for COM:
https://docs.microsoft.com/en-us/previous-versions/ms364069(v=vs.80)#calling-into-the-framework
But it does not seem to be useful at all, as the TimeSpan
is an immutable object whose value can be set only via a constructor with parameter or static factory method. None of these can be called via COM, afaik.
I'm hoping there's some trick. For instance one can create the TimeSpan
indirectly using the following C# code that could theoretically be convertible to COM, was the DateTime
class exposed to COM (what it is not, contrary to the TimeSpan
):
new DateTime().AddMilliseconds(1000).TimeOfDay;
Obviously I can implement my own .NET assembly exposed to COM with some factory method. But I'm hoping for a solution using "standard" .NET libraries or a plain VBA code only.
TimeSpan
. I don't think there is a way of initiating aTimeSpan
in VBA even using late-binding... I don't know this if of any help to you but you could have twoDate
type variables and calculate theTimeSpan
usingDateDiff()
function – user2140173 Apr 15 '14 at 9:06mscorlib.tlb
you can use the .Net's classes. Unfortunately, theTimeSpan
is a struct/Type which can't be initiated in VBA.Variable uses an automation type not supported in Visual Basic
– user2140173 Apr 15 '14 at 9:26TimeSpan
over COM, right? – Martin Prikryl Apr 15 '14 at 11:24