Automation in MS – Excel

Most of windows applications support Automation. Microsoft uses COM technology to enable automation. Automating Excel is very use full for practical applications. Use class wizard to create classes for automation servers. Open
class wizard , click Add Class->From Type Library, select File as type all files and select EXCEL.exe (It is available for excel10 at \Program Files\Microsoft Office\Office10\Excel.exe).

Select following classes

_Application, Workbooks, _Workbook, Worksheets, _Worksheet, Range

All above classes are derived from IDispatch interface. See code below to fill excel sheet with some values
Note: Use m_Range.SetValue to set value to the range.

VARIANT varEmpty;
varEmpty.vt = VT_ERROR;
varEmpty.scode = DISP_E_PARAMNOTFOUND;

m_workBooks = m_Application.GetWorkbooks();
m_workBook = m_workBooks.Add(varEmpty);
m_workSheets = m_workBook.GetWorksheets();
m_workSheet = m_workSheets.GetItem(COleVariant(short(1)));
m_Range = m_workSheet.GetRange(COleVariant(_T("A1")),covOptional);
m_Range = m_Range.GetResize(COleVariant((short)2),COleVariant((short)2));


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: