I'm trying to get the value of a cell using this: Globals.Sheet3.Cells.Range["A2"].Val开发者_StackOverflowue2 as string; Cell A2 refers to a cell on a different sheet that in turn refers to a formula on another sheet. The code above always returns null. How can I get the text of cell a2?
If you use...
VB.Net
Dim res As String
res = ThisWorkbook.Worksheets("Sheet3").Range("A2").Value2.ToString()
C#
String res = "";
res = ThisWorkbook.Worksheets["Sheet3"].Range("A2").Value2.ToString()
Does that work?
It's not clear from the question if the problem is with a section of VB.Net or C# code, however I'd say the problem is either with the way your a using the Range method, or possibly with your use of the Globals object.
UPATE to QUESTION: Based on feedback from the questioner, the ANSWER to this question is to use code such as... C#
String res = "";
res = ThisWorkbook.Worksheets["Sheet3"].Range("A2").Text
精彩评论