Close excel workbook

Hi All. So This is quite a common topic but no one seems to have an answer of yet. The excel file I am creating keeps opening which I dont want it to do. Is there a node that can either keep it closed or force it to close afterwards?

@technitutors , hi

seems to be a older topic

yes but no ones solved it, I tried the node within that topic doesnt work

okay got it with the passthrough node

1 Like

@technitutors ,

what do you have in your PythonScript? whats your input?

the input is just some excel script I found on the internet. The PythonScript is the one I found on that other topic you sent

@technitutors Just to add to the solution here I am pasting the code which is workable,

from System.IO import Directory
import re
import time
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import subprocess
import os
import errno
import csv
import clr
clr.AddReferenceByName('Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c')
from Microsoft.Office.Interop import Excel
from Microsoft.Office.Interop.Excel import ApplicationClass
from System.Runtime.InteropServices import Marshal

true_false = IN[0]

def excel_close(_bool):
    if _bool: 
        xlApp = Marshal.GetActiveObject("Excel.Application")	
        xlApp.Visible = True
        xlApp.DisplayAlerts = False
        xlApp.Workbooks.Close()
        xlApp.Quit()
        Check =  "Success"
    else:
        Check = "Set the boolean to True"

    return Check

OUT = excel_close(true_false)