I have excel with more than 1 million row, and I cannot open it with excel app, when I use UiPath it will freeze, is there any way to protect the file? I just want to protect the file and nothing else (no read, no write etc) just protect with password, thank you ![]()
Try to use invoke code activity with some vb.net code inside it.
Check the below one for reference
Dim excelApp As New Microsoft.Office.Interop.Excel.Application
excelApp.DisplayAlerts = False
excelApp.Visible = False
Dim wb As Microsoft.Office.Interop.Excel.Workbook =
excelApp.Workbooks.Open(filePath)
wb.Password = password
wb.Save()
wb.Close(False)
excelApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(wb)
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp)
Hope it helps!!
Regards,
Pravallika
I have created the VB.NET code for you to test:
Just use an Invoke Code activity with this inside:
Dim excelApp As New Microsoft.Office.Interop.Excel.Application
Dim workbook As Microsoft.Office.Interop.Excel.Workbook
Dim sheet As Microsoft.Office.Interop.Excel.Worksheet
Try
excelApp.DisplayAlerts = False
workbook = excelApp.Workbooks.Open("YourPathToWorkbook")
sheet = CType(workbook.Sheets("Sheet1"), Microsoft.Office.Interop.Excel.Worksheet)
' Protect worksheet (locks cells, prevents edits)
sheet.Protect("YourPassword")
workbook.Save()
workbook.Close()
excelApp.Quit()
Finally
System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet)
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook)
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp)
End Try
That should work - let me know ![]()
I dont know if it will live up to your requirements, but you could consider zipping it in a password protected archive.
This of course requires that no one will need to access the file (which is impossible anyway?)
Regards
Soren
Thank you very much for the reply, I’ll try it and get back to you
Thank you very much for the reply, I’ll try it and get back to you if it’s work
Thank you for the reply. This was actually the first approach that came to my mind as well. However, the requirement is to keep the file easily accessible without the need to zip and unzip it. The goal is mainly to prevent the file from being modified, rather than restricting access to it.
Then perhaps editing folder permissions would be a good approach?
You can deny modifying/writing the file.



