cancel
Showing results for 
Search instead for 
Did you mean: 

Convert a file to read only

SanjayBasnet
Level 2
I have an excel file (.xlsm) and I want to convert it to read only mode. How to do this ?
4 REPLIES 4

ritansh.jatwani
Level 9
Hi @Sanjay Basnet,

Did you try using code stage?​

Hi Sanjay,

You can try the below code to open any excel in read-only mode.
You can modify this to save as well.


Sub VBA_Open_Workbook_As_Read_Only()
Dim sFileName As String sFileName = "D:\test.xlsm"
Workbooks.Open Filename:=sFileName, ReadOnly:=True
End Sub

SanjayBasnet
Level 2
Hi @krishna.kodimurali9, I tried this code bit but I am getting a lot of compile errors in it.

36774.png

EVIPUTI
MVP
@Sanjay Basnet Create a duplicate of any action from Ms-Excel VBO and than use the code given by Murali . It will work , it works for me .

You can follow the steps below.

1. Go to "Open Workbook" page and duplicate it.

2. Go to "Open Workbook - Copy" page and open the "Open Workbook" code stage.

3. Replace the code by this code below and rename this stage and page

Dim wb as Object = GetInstance(handle).Workbooks.Open(FileName:=filename,ReadOnly:=True)
name = wb.Name
wb.Activate()

4. That's all. And you can public this page and use it.

Or you can add any parameters if you need them to do some excel manipulation.

Example

Dim wb as Object = GetInstance(handle).Workbooks.Open(filename,UpdateLinks:=updatelinks,ReadOnly:=readonly1,Password:=password,WriteResPassword:=writerespassword,IgnoreReadOnlyRecommended:=True)
name = wb.Name
wb.Activate()
------------------------------ Vipul Tiwari Senior Process Simplification Developer Amazon ------------------------------