If an Excel file is "Read Only Recommended", how do I write to it?

There’s a particular Excel file (.xlsx file) I’m trying to write to using UiPath’s Excel activities, but whenever I try to open it I get the prompt “The author would like you to open [file name] as read-only unless you need to make changes. Open as read-only?” and I can’t proceed unless I click “No” in the dialog box. Is there any activity I can use to modify the file so it’s no longer Read Only Recommended?

The creator of the file enabled the Read-only option when the file was saved. You may have to ask the author of the file to resend you a file with this option removed.

Alternately, as a one time action you may want to remove this option yourself. There are several ways to do this as described in the article below.

If both options are not possible, then you may have to factor in this obstacle in your automation and then have the Robot click on the Read-only option, save the file with a new name and work with the copy of the file instead. I haven’t tried it, but theoretically it must be possible.

We are working with RPA after all. Don’t like something, give it to your Robot sidekick! :wink:

If you HAVE to fix this during runtime, this is what I wrote for when i had that scenario:

put this in an Invoke Code activity, pass in the filepath argument.

Try
	Dim xlApp As Microsoft.Office.Interop.Excel._Application = Nothing  
	Dim xlWorkBooks As Microsoft.Office.Interop.Excel.Workbooks=Nothing  
	Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook=Nothing  
	'Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet=Nothing  
	'Dim xlWorkSheets As Microsoft.Office.Interop.Excel.Sheets=Nothing  
	'xlApp=New Microsoft.Office.Interop.Excel.ApplicationClass
	xlApp.DisplayAlerts=False
	xlApp.Visible = True
	xlWorkBooks=xlApp.Workbooks
	xlWorkBook=xlWorkBooks.Open(filepath,ReadOnly:=False,IgnoreReadOnlyRecommended:=True)
	'out_wb = xlWorkBook
	
	
	io_readOnlyRecommended = xlworkbook.ReadOnlyRecommended
	If io_readOnlyRecommended
		console.WriteLine("Read only recommended. turn off")
		xlworkbook.ReadOnlyRecommended = False	
	Else
		Console.WriteLine("ReadOnlyRecommended is False")
	End If
	
	xlWorkBook.Save()
	'xlWorkBook.Close() 
	'xlApp.Quit()
Catch ex As Exception
	Throw New system.Exception("unable to turn off ReadOnlyRecommended, save on excel. "+ex.Message)
End Try	
2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.