in VBA, I have a global script control variable in JScript language (Javascript ES3). I have the var "ThisWorkbook" set as
var ThisWorkbook = GetObject('', 'Excel.Application').Workbooks('" + ThisWorkbook.Name + "')
Then I can close the workbook by saying
ThisWorkbook.Close(false)
Full VBA code for completion:
Sub Test
Dim ScriptC as Object
Set ScriptC = CreateObject("ScriptControl"): ScriptC.Language = "JScript"
ScriptC.Eval "var ThisWorkbook = GetObject('', 'Excel.Application').Workbooks('" + ThisWorkbook.Name + "')"
ScriptC.Eval "ThisWorkbook.Close(false)"
End Sub
However, this crashes my Excel and all open workbooks (Excel 2016) - what would be a good way to avoid this? I have to do this from JScript/Javascript, but could for example do it through a WScript variable (as long as it's called from within JScript). The reason for this is that it's triggered by an event that's evaluated in JScript and not in VBA (VBA is just the wrapper in this case).
I've tried "ThisWorkbook.Application.Quit' (as per https://docs.microsoft.com/en-us/office/vba/api/excel.application.quit ), but that doesn't work either.
Thanks!
ThisWorkBook
to any other wordMyWorkBook
or Something. – MikkuThisWorkBook.Close False
– Mikku