Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Programmatically Restart Excel

When users change certain configuration options in my Excel add-in I need
them to restart Excel to have them applied - for example, the user interface
language. I can either information the user that they need to restart or
close Excel and require them to restart it. What I want to do is
programmatically restart Excel like Excel does itself when you get the
message Excel has encountered a problem and needs to restart. Is there a way
I can have my add-in shut down Excel so it will automatically restart?

- Drew
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Programmatically Restart Excel

You could create a Windows task, which will start Excel or you could pass
control to a VB6 .exe file. Not sure there is a simpler way as if Excel is
closed it can't start Excel, unless Excel starts a second instance of Excel
and
then closes itself with Quit. Just some quick thoughts and I am sure
somebody
will come up with a better answer.

RBS


"Drew Lettington" wrote in
message ...
When users change certain configuration options in my Excel add-in I need
them to restart Excel to have them applied - for example, the user
interface
language. I can either information the user that they need to restart or
close Excel and require them to restart it. What I want to do is
programmatically restart Excel like Excel does itself when you get the
message Excel has encountered a problem and needs to restart. Is there a
way
I can have my add-in shut down Excel so it will automatically restart?

- Drew


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 284
Default Programmatically Restart Excel

Drew,

Below is one option. The subroutine writes a vbs file to the temp folder
then it launches the vbs file immediately before saving the workbook and
closing Excel. The first line in the vbs file causes a 10 second pause to
allow Excel time to shut down, then it launches Excel and opens the workbook
from whence it came and finally deletes itself from the temp folder.

______________________________________

Sub RestartMe()

strXLfile = ThisWorkbook.FullName

Set fso = CreateObject("Scripting.FileSystemObject")

strRestarter = fso.GetSpecialFolder(2) & "\restartWkbk.vbs"
Set fileRestart = fso.CreateTextFile(strRestarter)

With fileRestart
.WriteLine "WScript.Sleep 10000"
.WriteLine "Set fso = CreateObject(" & Chr(34) _
& "Scripting.FileSystemObject" & Chr(34) & ")"
.WriteLine "Set objXL = CreateObject(" & Chr(34) _
& "Excel.Application" & Chr(34) & ")"
.WriteLine "objXL.Visible = True"
.WriteLine "objXL.Workbooks.Open(" & Chr(34) _
& strXLfile & Chr(34) & ")"
.WriteLine "fso.DeleteFile " & Chr(34) & strRestarter & Chr(34)
.Close
End With

strCmdRstrt = "WScript.exe " & strRestarter

Shell (strCmdRstrt)

ThisWorkbook.Save
Application.Quit

Set fso = Nothing

End Sub

______________________________________

Steve Yandl




"Drew Lettington" wrote in
message ...
When users change certain configuration options in my Excel add-in I need
them to restart Excel to have them applied - for example, the user
interface
language. I can either information the user that they need to restart or
close Excel and require them to restart it. What I want to do is
programmatically restart Excel like Excel does itself when you get the
message Excel has encountered a problem and needs to restart. Is there a
way
I can have my add-in shut down Excel so it will automatically restart?

- Drew



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 284
Default Programmatically Restart Excel

Drew,

Since you say you're running all of this from an add-in rather than the
active workbook, you should probably replace ThisWorkbook with
ActiveWorkbook in the sub.

Sub RestartMe()

strXLfile = ActiveWorkbook.FullName

Set fso = CreateObject("Scripting.FileSystemObject")

strRestarter = fso.GetSpecialFolder(2) & "\restartWkbk.vbs"
Set fileRestart = fso.CreateTextFile(strRestarter)

With fileRestart
.WriteLine "WScript.Sleep 10000"
.WriteLine "Set fso = CreateObject(" & Chr(34) _
& "Scripting.FileSystemObject" & Chr(34) & ")"
.WriteLine "Set objXL = CreateObject(" & Chr(34) _
& "Excel.Application" & Chr(34) & ")"
.WriteLine "objXL.Visible = True"
.WriteLine "objXL.Workbooks.Open(" & Chr(34) _
& strXLfile & Chr(34) & ")"
.WriteLine "fso.DeleteFile " & Chr(34) & strRestarter & Chr(34)
.Close
End With

strCmdRstrt = "WScript.exe " & strRestarter

Shell (strCmdRstrt)

ActiveWorkbook.Save
Application.Quit

Set fso = Nothing

End Sub


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Programmatically Restart Excel

Thanks RB and Steve. I'm going to try something similar to what you've
suggested. I think I'll write a small application to start Excel. The
add-in will call the application prior to closing Excel, passing a parameter
with the process ID of the currently running Excel process. The application
will check to see then the process is no longer available and then will start
Excel.

- Drew

"Steve Yandl" wrote:

Drew,

Below is one option. The subroutine writes a vbs file to the temp folder
then it launches the vbs file immediately before saving the workbook and
closing Excel. The first line in the vbs file causes a 10 second pause to
allow Excel time to shut down, then it launches Excel and opens the workbook
from whence it came and finally deletes itself from the temp folder.

______________________________________

Sub RestartMe()

strXLfile = ThisWorkbook.FullName

Set fso = CreateObject("Scripting.FileSystemObject")

strRestarter = fso.GetSpecialFolder(2) & "\restartWkbk.vbs"
Set fileRestart = fso.CreateTextFile(strRestarter)

With fileRestart
.WriteLine "WScript.Sleep 10000"
.WriteLine "Set fso = CreateObject(" & Chr(34) _
& "Scripting.FileSystemObject" & Chr(34) & ")"
.WriteLine "Set objXL = CreateObject(" & Chr(34) _
& "Excel.Application" & Chr(34) & ")"
.WriteLine "objXL.Visible = True"
.WriteLine "objXL.Workbooks.Open(" & Chr(34) _
& strXLfile & Chr(34) & ")"
.WriteLine "fso.DeleteFile " & Chr(34) & strRestarter & Chr(34)
.Close
End With

strCmdRstrt = "WScript.exe " & strRestarter

Shell (strCmdRstrt)

ThisWorkbook.Save
Application.Quit

Set fso = Nothing

End Sub

______________________________________

Steve Yandl




"Drew Lettington" wrote in
message ...
When users change certain configuration options in my Excel add-in I need
them to restart Excel to have them applied - for example, the user
interface
language. I can either information the user that they need to restart or
close Excel and require them to restart it. What I want to do is
programmatically restart Excel like Excel does itself when you get the
message Excel has encountered a problem and needs to restart. Is there a
way
I can have my add-in shut down Excel so it will automatically restart?

- Drew






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 284
Default Programmatically Restart Excel

Drew,

I thought about setting the vbs file to monitor for the Excel process being
shut down using WMI but wasn't certain that the systems would all have WMI
installed (Win 98 would not). Also, when you're having the
Scripting.FileSystemObject create the vbs file by writing line by line, it
gets to be cumbersome when you have WMI statements with lots of punctuation
marks. It's certainly more straightforward to have your application already
set to go and passing it an appropriate argument but that means you need to
have the helper application in place before your users run your routine.

Steve



"Drew Lettington" wrote in
message ...
Thanks RB and Steve. I'm going to try something similar to what you've
suggested. I think I'll write a small application to start Excel. The
add-in will call the application prior to closing Excel, passing a
parameter
with the process ID of the currently running Excel process. The
application
will check to see then the process is no longer available and then will
start
Excel.

- Drew

"Steve Yandl" wrote:

Drew,

Below is one option. The subroutine writes a vbs file to the temp folder
then it launches the vbs file immediately before saving the workbook and
closing Excel. The first line in the vbs file causes a 10 second pause
to
allow Excel time to shut down, then it launches Excel and opens the
workbook
from whence it came and finally deletes itself from the temp folder.

______________________________________

Sub RestartMe()

strXLfile = ThisWorkbook.FullName

Set fso = CreateObject("Scripting.FileSystemObject")

strRestarter = fso.GetSpecialFolder(2) & "\restartWkbk.vbs"
Set fileRestart = fso.CreateTextFile(strRestarter)

With fileRestart
.WriteLine "WScript.Sleep 10000"
.WriteLine "Set fso = CreateObject(" & Chr(34) _
& "Scripting.FileSystemObject" & Chr(34) & ")"
.WriteLine "Set objXL = CreateObject(" & Chr(34) _
& "Excel.Application" & Chr(34) & ")"
.WriteLine "objXL.Visible = True"
.WriteLine "objXL.Workbooks.Open(" & Chr(34) _
& strXLfile & Chr(34) & ")"
.WriteLine "fso.DeleteFile " & Chr(34) & strRestarter & Chr(34)
.Close
End With

strCmdRstrt = "WScript.exe " & strRestarter

Shell (strCmdRstrt)

ThisWorkbook.Save
Application.Quit

Set fso = Nothing

End Sub

______________________________________

Steve Yandl




"Drew Lettington" wrote in
message ...
When users change certain configuration options in my Excel add-in I
need
them to restart Excel to have them applied - for example, the user
interface
language. I can either information the user that they need to restart
or
close Excel and require them to restart it. What I want to do is
programmatically restart Excel like Excel does itself when you get the
message Excel has encountered a problem and needs to restart. Is there
a
way
I can have my add-in shut down Excel so it will automatically restart?

- Drew






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
start Word and Mail Merge the data from excel,system will restart tmssupport Excel Discussion (Misc queries) 2 December 18th 07 03:15 PM
After pasting a Chart in Word, excel makes a "restart" Carlo Excel Programming 2 September 21st 06 06:52 AM
How to de-install a new update to restart excel Sanjay Ghoshal Excel Discussion (Misc queries) 0 July 18th 06 07:53 AM
'Do Until...' Restart Jack Excel Programming 3 June 22nd 06 09:03 AM
Excel 12, insert chart does not work. Exel restart. Why? tujauja Charts and Charting in Excel 1 March 27th 06 12:45 AM


All times are GMT +1. The time now is 01:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"