What is the C # equivalent of this Excel VBA code for Shapes?

This is the VBA code for an Excel template that I am trying to convert to C # in the VSTO project I'm working on. By the way, this is a VSTO add-in:

Dim addedShapes() As Variant
ReDim addedShapes(1)
addedShapes(1) = aBracket.Name

ReDim Preserve addedShapes(UBound(addedShapes) + 1)
addedShapes(UBound(addedShapes)) = "unique2"

Set tmpShape = Me.Shapes.Range(addedShapes).Group

At this moment I am puzzled addedShapes(), not sure what it is.

Update: Matti mentioned what addedShapes()a variant array is in VBA. So now I wonder what should be in the content addedShapes(). Would this be the correct way to call Shapes.Range () in C #?

List<string> addedShapes = new List<string>();
...
Shape tmpShape = worksheet.Shapes.get_Range
  (addedShapes.Cast<object>().ToArray()).Group();

I would be grateful to everyone who worked with VBA and C # to comment on my questions and problems!

+3
source share
2 answers

, , addedShapes - . VB () [].

, :

object[] addedShapes = new object[] { aBracket.Name, "unique2" };
Shape tmpShape = worksheet.Shapes.get_Range(addedShapes).Group();

Shape tmpShape = worksheet.Shapes[addedShapes].Group();

, - . , MSDN .

+2

c, vb hilight .

//This declares an array of variants but does not initialize it.
Dim addedshapes() As Variant

//Initializes the array with a max index of 1. (insert vb index rant here)
ReDim addedShapes(1)

//assigns the contents of aBracket.Name to element 1 of the array.
addedShapes(1) = aBracket.Name 

//increases the size of addedShapes by 1, retaining any values.
ReDim Preserve addedShapes(UBound(addedShapes) + 1) 

//sets the last element to the string literal
addedShapes(UBOund(addedShapes)) = "unique2" 

//Not sure here because I havent done any VBA in a loooong time,
//but anyway it passing the array.
set tmpShape = Me.Shapes.Range(addedShapes).Group 

VB, Variant - , , int, float, objects .., .Net / . , , , . List<object> List<Class> List<BaseClass> List<ISomeInterface>

+2

Source: https://habr.com/ru/post/1746064/


All Articles