Community
Hello, I create a ilogic rule to write an excel file. I need a code to check if this excel file it's open before write it.
Thanks in advance,
Solved! Go to Solution.
Solved by RodrigoEiras. Go to Solution.
Hi,
I found this piece of code in another thread in the forum. I think it can be what you are looking for:
'excel file name Dim Filename As String = "c:\temp\GGGGG.xlsx" 'Step 1. Close workbook if it is already opened Dim excelApp As Object Try excelApp = GetObject(, "Excel.Application") For Each wb As Object In excelApp.workbooks If UCase(wb.fullname) = UCase(filename) Then 'workbook is already opened: Save and close it wb.Save wb.Close Exit For End If Next Catch Finally excelApp = Nothing End Try 'Step 2. Open file from disk and fill with iProperties GoExcel.Open(Filename) GoExcel.CellValue("A2")=iProperties.Value("Project", "Part Number") GoExcel.CellValue("A3")=iProperties.Value("Project", "Description") GoExcel.Save GoExcel.Close Beep MsgBox("FILE IS UPDATED")
Thanks. I found this other piece of code. I tried it and it works ok.
SyntaxEditor Code Snippet
Try Dim fs As System.IO.FileStream = System.IO.File.OpenWrite("excel.xlsx") fs.Close() Catch ex As System.IO.IOException ExcelTancat = False End Try