Set name ranges in Excel using C #?

I am trying to replicate this VBA passcode using C #, but cannot do this. Wonder if anyone else has tried this before and can help.

oWB.Worksheets ("Signoff"). Range ("rgSignOffRecTemplate"). Value = g_TemplatePath and "Signoff_Rec.XLT"

rgSignOffRecTemplate is the "Specific Name" in the Excel template I'm trying to write.

Many thanks for your help.

+1
source share
1 answer
private void ThisWorkbook_Startup(object sender, System.EventArgs e) { Excel.Name oName; Excel.Range oRange; //'using name oName = ExcelWorkbook1.Globals.ThisWorkbook.Names.Item("rgSignOffRecTemplate", missing, missing); oName.RefersToRange.Value2 = "here"; //'using range oName = this.Names.Item("rgSignOffRecTemplate", missing, missing); oRange = oName.RefersToRange; oRange.Value2 = "here i am"; //'direct access this.Names.Item("rgSignOffRecTemplate", missing, missing).RefersToRange.Value2 = "here i am again"; DisplayWorkbookNames(); } private void DisplayWorkbookNames() { for (int i = 1; i <= this.Names.Count - 1; i++) { Globals.Sheet1.Range["A" + i.ToString(), missing].Value2 = this.Names.Item(i, missing, missing); } } 
+5
source

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


All Articles