views:

9

answers:

1

I'm opening an excel worksheet using the Microsoft.Office.Interop.Excel COM interface. I'm trying to adjust the "maximum" value of a scroll bar embedded into a worksheet. I can find the scroll bar with the following:

app = new Excel.Application();
wb = app.Workbooks.Open(
  Path.GetDirectoryName(Application.ExecutablePath)+@"\template.xls",
  Type.Missing, Type.Missing, Type.Missing, Type.Missing,
  Type.Missing, Type.Missing, Type.Missing, Type.Missing,
  Type.Missing, Type.Missing, Type.Missing, Type.Missing,
  Type.Missing, Type.Missing);

for (int sheetNum = 1; sheetNum < wb.Sheets.Count + 1; sheetNum++)
{
  ws = (Excel.Worksheet)wb.Sheets[sheetNum];
  if (ws.Name == "Graphic")
  {
    foreach (Excel.Shape ctrl in ws.Shapes)
    {
      if (ctrl.Name == "graphicScroll")
      {
        // how do a cast this??
        break;
      }
    }
  }
  break;
}

Once I get the shape object though, I can not figure out the proper cast so that I can adjust it's properties.

Any ideas?

Thanks.

A: 

Figured it out. I should be iterating the OLEObjects and casting to Microsoft.Vbe.Interop.Forms

Excel.OLEObjects objects = (Excel.OLEObjects) ws.OLEObjects(Type.Missing);
foreach (Excel.OLEObject ctrl in objects)
{
  if (ctrl.Name == "graphicScroll")
  {                         
    ((Microsoft.Vbe.Interop.Forms.ScrollBar) ctrl.Object).Max = readsAtDeltaMinKeys[readsAtDeltaMin.Count-1];
  }
}
Mark