VB.Net:从行和列获取单元格地址

我知道这个问题之前已经被问过了,但是我已经试过对他们俩的答案,也没有为我工作过。

当前代码:

Dim aString As String Dim address As String For Each thisTriangle In triangleArray drawTriangle(rowToDrawIn, thisTriangle.getMarkedCell) aString = String.Format("Activity Name: {0}", thisTriangle.getActivityDescription) //here is where I am trying to get the address address = xlWorkSheet.Cells.Address(rowToDrawIn, thisTriangle.getMarkedCell) xlWorkSheet.Range(address).AddComment(aString) Next 

正如你所看到的,我正试图获得地址,然后在该地址发表评论。 运行此代码时,我收到运行时错误。 thisTriangle.getMarkedCell返回一个int作为列号, thisTriangle.getMarkedCell返回行号。

任何和所有的帮助,非常感谢。

假设rowToDrawInthisTriangle.getMarkedCell都是正整数。

你的错在这里Cells.Address 。 如果你传递Cells.Address(1,2)你期望得到$B$1但实际上你得到$1:$10485761 ,现在你正在尝试添加注释到这个范围,因此参数错误。

Cells.Address(1,2)!= Cells(1,2).Address

改变这一点

  address = xlWorkSheet.Cells.Address(rowToDrawIn, thisTriangle.getMarkedCell) xlWorkSheet.Range(address).AddComment(aString) 

 xlWorkSheet.Cells.(rowToDrawIn, thisTriangle.getMarkedCell).Comment.Delete xlWorkSheet.Cells.(rowToDrawIn, thisTriangle.getMarkedCell).AddComment(aString)