Возможно ли использовать библиотеки .NET в макросах для Word на VB? - VBA
Формулировка задачи:
Нужно написать костыль на пару десятков строк, сижу и понимаю что с .NET я это сделаю за 20 минут, а пока изучу этот VB пол дня пройдет. Есть возможность пользоваться библиотеками .NET в макросах?
Решение задачи: «Возможно ли использовать библиотеки .NET в макросах для Word на VB?»
textual
Листинг программы
In this article by the Scripting Guys an alternative technique is discussed: ArrayLists.
The ArrayList is a .NET Framework class, which means it requires the .NET Framework.
The following code is used to create an ArrayList and "populate" it with some data:
' this code creates and populates an ArrayList
Set myArrayList = CreateObject( "System.Collections.ArrayList" )
myArrayList.Add "F"
myArrayList.Add "B"
myArrayList.Add "D"
myArrayList.Add "C"
Now, to add an element and sort the ArrayList, all we need to do is:
' [1] add the new element to the ArrayList
myArrayList.Add "Z"
' [2] sort the ArrayList
myArrayList.Sort
или вот рабочий пример
Function Unique(DRange As Variant) As Variant
Dim Dict As Object, Result As Object
Dim i As Long, j As Long, NumRows As Long, NumCols As Long
If TypeName(DRange) = "Range" Then DRange = DRange.Value2
NumRows = UBound(DRange)
NumCols = UBound(DRange, 2)
Set Dict = CreateObject("System.Collections.HashTable")
For i = 1 To NumCols
For j = 1 To NumRows
If Len(DRange(j, i)) Then
Dict(DRange(j, i)) = DRange(j, i)
End If
Next j
Next i
Set Result = CreateObject("System.Collections.ArrayList")
Result.AddRange Dict.Keys
Result.Sort
Unique = Application.WorksheetFunction.Transpose(Result.ToArray)
End Function