{"id":3349,"date":"2018-11-10T11:02:37","date_gmt":"2018-11-10T11:02:37","guid":{"rendered":"http:\/\/officetuts.net\/excel\/?p=3349"},"modified":"2024-03-29T15:55:39","modified_gmt":"2024-03-29T15:55:39","slug":"open-workbook-as-read-only","status":"publish","type":"post","link":"https:\/\/officetuts.net\/excel\/vba\/open-workbook-as-read-only\/","title":{"rendered":"VBA Open Workbook as Read-only"},"content":{"rendered":"\n
If you want to use the VBA code to open a workbook in read-only mode, you have to follow these steps.<\/p>\n\n\n\n
Sub OpenWorkbook()\n Dim my_wb As Workbook\n Dim file_path As String\n \n file_path = \"C:\\excel_file.xlsx\"\n \n Set my_wb = Workbooks.Open(Filename:=file_path, ReadOnly:=True)\nEnd Sub<\/pre>\n\n\n\n\n
- Create the file called excel_file.xlsx on the C drive (or any other path. Just remember to change the code accordingly).<\/li>\n\n\n\n
- Run the code.<\/li>\n\n\n\n
- Now, you have the file opened in a new window.<\/li>\n<\/ol>\n\n\n\n