Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbscript DisplayAlerts not working with excel automation

Status
Not open for further replies.

blpcrs

Programmer
Aug 25, 2011
19
US
Hi, my first post, I am trying to get a script together that will
Open an 03, 07 or 10 excel application, all on the same PC, passing into the script file and version.
Then I perform some operations and leave it open so another automation tool may interact with it and closed the app ala Alt-F4.

however, the objExcel.DisplayAlerts = False does not work, as I am still prompted on shutdown if I want to save.

code:
...
FileName = WScript.Arguments.Item(0)
XLVersion = WScript.Arguments.Item(1)

if XLVersion = 11 then
XLPath = """C:\Program Files\Microsoft Office\Office11\Excel.exe"" "& "/automation -Embedding"
elseif XLVersion = 12 then
XLPath = """C:\Program Files\Microsoft Office\Office12\Excel.exe"" "& "/automation -Embedding"
elseif XLVersion = 13 then
XLPath = """C:\Program Files\Microsoft Office\Office13\Excel.exe"" "& "/automation -Embedding"
elseif XLVersion = 14 then
XLPath = """C:\Program Files\Microsoft Office\Office14\Excel.exe"" "& "/automation -Embedding"
else
XLPath = """C:\Program Files\Microsoft Office\Office12\Excel.exe"" "& "/automation -Embedding"
end if

set oWSH = CreateObject("WScript.Shell")
Ret = oWSH.Run(XLPath, 1, False)

Set objExcel = GetObject("","Excel.Application")

objExcel.Visible = TRUE
objExcel.WindowState = xlMaximized
objExcel.DisplayAlerts = False


Set objWorkbook = objExcel.Workbooks.Open(FileName)


---after this, i basically load an addin, then perform some operations to change zoom levels, maximize window, turn off cleartype... and final line of the vbs is

set objExcel = Nothing

---I've tested the value of objExcel.DisplayAlerts and it says False, but when I close Excel, I still get the popup. Ideas? Am I missing something? thank you in advance!
 
Greetings all -- since it seems like no one has a solution that could solve this, I was forced to kick off a separate script at the point I needed to close excel.


Set objExcel = GetObject(,"Excel.Application")
objExcel.DisplayAlerts = FALSE
objExcel.ActiveWorkbook.Close(FALSE)
objExcel.application.quit

 
You could also ungracefully kill the excel process

Code:
sub killProcess(strProcessName)
	set colProcesses = GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * from Win32_Process Where Name='" & strProcessName & "'")
	if colProcesses.count <> 0 then
		for each objProcess in colProcesses
			objProcess.Terminate()
		next
	end if
end sub 

killProcess "excel.exe"

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top