Hi,
Does anybody know how to start a new work book from a windows form? I found this on Microsoft's website but I keep getting the error message "The Name m_objExcel does not exsist in the current context".
using
System;using
System.Collections.Generic;using
System.Drawing;using
System.Windows.Forms;using
Microsoft.Office.Interop.Excel;using
Excel;namespace
copy{
/// <summary>///
Description of MainForm. /// </summary> public partial class MainForm : Form { public MainForm(){
InitializeComponent();}
public void Button1Click(object sender, EventArgs e){
m_objExcel = new Excel.Application(); m_objBooks = (Excel.Workbooks)m_objExcel.Workbook;m_objBook = (Excel._Workbook)(m_objBooks.Add(m_objOpt));
}
}
}
Thanks in advance...
CGPosted Jan 15, 2009, 6:00 AM
Thanks for your replies. I have my form working now but when I Quit(); the process dosen't. How do I release this from task manager?
Thanx in advance
Guest UserPosted Jan 5, 2009, 10:44 AM
Guest UserPosted Jan 5, 2009, 10:39 AM
Excel.Range rng = (Excel.Range)m_objBook.Cells[6, 1];
rng.Value2 = "HELLO WORLD!";
Don't forget to execute the Quit() method on your Excel.Application object when you're finished with it. It won't shut down independently - you have to do it manually. If you don't, you'll have an EXCEL.EXE process running in the background, using up resources. The Quit method will hang if you have unsaved changes to your worksheet (because it will be trying to prompt you to save your changes), so make sure you save the workbook before using Quit().
CGPosted Jan 5, 2009, 8:57 AM
Of corse!!Silly me,
How can I select a different cell say...(A,6)?
Guest UserPosted Jan 2, 2009, 11:30 AM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
namespace ExcelOpen
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnOpenExcel_Click(object sender, EventArgs e)
{
Excel.Application m_objExcel = new Excel.Application();
m_objExcel.Workbooks.Add(Excel.XlSheetType.xlWorksheet);
Excel.Worksheet m_objBook = (Excel.Worksheet)m_objExcel.ActiveSheet;
}
}
}