Excel object library method to open a document in safe mode?

  • Thread starter sherifffruitfly
  • Start date
S

sherifffruitfly

I'm coming to Excel from C#, and need to open a document in Excel,
with no add-ins - how can I do this from Excel's object library? (For
Office 2003).


Thanks for any hints,

-sff
 
S

Shasur

Here is a hint

using Excel = Microsoft.Office.Interop.Excel;

private void OpenExcelWorkbook(string sXLFileName )
{
try
{
Object missing = System.Type.Missing;
oXL = new Excel.Application();
oXL.Visible = true;
Excel.Workbook oWB = oXL.Workbooks.Open(sXLFileName,
missing, missing, missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing,missing );

// processing

// close the workbook and quit the application
oWB.Close();
oXL.Quit();

}
catch (Exception ex)
{

}
}


Cheers
Shasur
 
S

sherifffruitfly

Here is a hint

using Excel = Microsoft.Office.Interop.Excel;

        private  void OpenExcelWorkbook(string sXLFileName )
        {
            try
            {
                Object missing = System.Type.Missing;
                oXL = new Excel.Application();
                oXL.Visible = true;
                Excel.Workbook oWB = oXL.Workbooks.Open(sXLFileName,
missing, missing, missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing,missing );

                // processing

                // close the workbook and quit the application
                oWB.Close();
                oXL.Quit();

            }
            catch (Exception ex)
            {

            }
        }

Cheers
Shasur
--http://vbadud.blogspot.com

Thanks for the reply.

Maybe I'm missing something, but your code looks like the *standard*
code to open Excel, which starts Excel in *full* mode, loading add-
ins.

I'm trying to open Excel in SAFE MODE. To be clear, I do NOT mean
Windows Safe Mode. I mean EXCEL safe mode, which may be done at the
command line as "excel.exe /safe". It is described here, for example:

http://www.cpearson.com/excel/StartupErrors.aspx


Thanks again,

-sff
 
S

Shasur

The following can give you a hint


System.Diagnostics.Process.Start("Excel.exe", "/Safe");
oXL =
(Excel.Application)Marshal.GetActiveObject("Excel.Application");

Cheers
Shasur
 
S

sherifffruitfly

The following can give you a hint

                System.Diagnostics.Process.Start("Excel.exe", "/Safe");
                oXL =
(Excel.Application)Marshal.GetActiveObject("Excel.Application");

Thank you!

As there may be several instances of Excel running, I still need to
figure out how to use ProcessId (or something) to get the right one,
but you've given me enough to get rolling.


Thanks again!

sff
 

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