How to start excel in "safe mode" programmatically

A

Abhishek - Oracle

Is there a way to start excel in "safe mode" programmatically.

I am creating an excel application instance as mentioned below:-

Excel.Application excelApp = new Excel.Application ();

I do not want to load add-ins and it's my understanding that the "safe mode"
suppresses all add-ins.

Also, I do not want to affect any other instances of the excel application
which may be running add-ins.

Please advise.

Thanks,
Abhishek
 
D

Dave Peterson

When I start an excel instance using MSWord, I have to load the addins that I
want to use--since none are loaded when I start Excel this way.

It's not quite safe mode--I still have to disable events in excel before I
open/change/close stuff.

Isn't that what you're seeing with your code and your new excel application?
 
H

Homey

maybe see this work ok

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hRegEdit As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Sub StartXLSafemode()
ShellExecute 0, "Open", "excel.exe", "/s", "", 1
End Sub

message | Is there a way to start excel in "safe mode" programmatically.
|
| I am creating an excel application instance as mentioned below:-
|
| Excel.Application excelApp = new Excel.Application ();
|
| I do not want to load add-ins and it's my understanding that the "safe
mode"
| suppresses all add-ins.
|
| Also, I do not want to affect any other instances of the excel application
| which may be running add-ins.
|
| Please advise.
|
| Thanks,
| Abhishek
 
A

Abhishek - Oracle

Thanks a lot for the suggestion.

I got something working using the code below :-

Systen.Diagnostics.Process myProcess = new Process ();
myProcess.StartInfo.FileName = "excel.exe";
myProcess.StartInfo.Arguments = "/safemode";
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start ();

I can run excel in safe mode as needed.

Now the only thing left is to get the Excel.Application instance from the
above process "myProcess".

I am trying "System.Runtime.InteropServices.Marshal.GetActiveObject" or
"System.Runtime.InteropServices.Marshal.BindToMoniker" without any success so
far.
Any ideas are welcome.

Thanks
Abhishek
 

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