Open PowerPoint and Excel documents with C#

G

Gidi

HI,

I'm trying to open Excel and PPT files, using C# code, and in both case the
application (excel or powepoint) is lanuched, but the file is not opened.

this is my code for opening Excel:

private void Open_Excel_File(string file_name)
{
try
{

object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
object count = 1;
object Background = true;
object PrintToFile = false;
object Collate = false;
object ActivePrinterMacGX = missing;
object ManualDuplexPrint = false;
object PrintZoomColumn = 1;
object PrintZoomRow = 1;

Microsoft.Office.Interop.Excel.ApplicationClass ExcelApp =
new Microsoft.Office.Interop.Excel.ApplicationClass();

ExcelApp.Visible=true;

Microsoft.Office.Interop.Excel.Workbook workBook =
ExcelApp.Workbooks.Open(file_name, missing, readOnly, missing, missing,
missing, missing, missing, missing, isVisible,
missing, missing, missing, missing, missing);

}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}


This is my code for opening the PPT file:

private void Open_PPT_File(string file_name)
{
try
{
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
object count = 1;
object Background = true;
object PrintToFile = false;
object Collate = false;
object ActivePrinterMacGX = missing;
object ManualDuplexPrint = false;
object PrintZoomColumn = 1;
object PrintZoomRow = 1;
Microsoft.Office.Interop.PowerPoint.Presentation presentation;

Microsoft.Office.Interop.PowerPoint.ApplicationClass PPTApp
= new Microsoft.Office.Interop.PowerPoint.ApplicationClass();

presentation =
PPTApp.Presentations.Open(file_name,Microsoft.Office.Core.MsoTriState.msoFalse,Microsoft.Office.Core.MsoTriState.msoFalse,Microsoft.Office.Core.MsoTriState.msoFalse);

PPTApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; ;

PPTApp.Activate();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}

Can anyone help me understand what's is the problem?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top