Open an existing Read Only Excel document
Open an existing Read Only Excel document
(OP)
I've reviewed the posts for something similar but have been unable to find anything. I have the following code snip...
Dim xlApp As Object
Dim ObjWorkbook As Object
Dim ObjWorksheet As Object
Set xlApp = CreateObject("Excel.Application")
xlApp.Application.DisplayAlerts = False
set ObjWorkbook = xlApp.Workbooks.Open ("S:\Dan\folder\file.xls")
xlApp.Visible = True
Set objWorksheet = xlApp.Sheets("sheet1")
The file "S:\Dan\folder\file.xls" is saved as a password protected file and I want to open a "Read Only" version. In VBA, I know how to do this as...
Workbooks.Open Filename:="s:\Dan\folder\file.xls", _ReadOnly:=True
Set shSheet = Worksheets("Sheet1")
How can I open this file as a read only type? What is the correct syntax?
Dim xlApp As Object
Dim ObjWorkbook As Object
Dim ObjWorksheet As Object
Set xlApp = CreateObject("Excel.Application")
xlApp.Application.DisplayAlerts = False
set ObjWorkbook = xlApp.Workbooks.Open ("S:\Dan\folder\file.xls")
xlApp.Visible = True
Set objWorksheet = xlApp.Sheets("sheet1")
The file "S:\Dan\folder\file.xls" is saved as a password protected file and I want to open a "Read Only" version. In VBA, I know how to do this as...
Workbooks.Open Filename:="s:\Dan\folder\file.xls", _ReadOnly:=True
Set shSheet = Worksheets("Sheet1")
How can I open this file as a read only type? What is the correct syntax?
RE: Open an existing Read Only Excel document
If not ObjWorkbook.ReadOnly then
objWorkbook.ChangeFileAccess Mode:=xlReadOnly, WritePassword:="admin"
end if
xlApp.Visible = True
Sometimes you gotta leave your zone of safety. You have to manufacture Inspirado. You gotta get out of the apartment. You've got to run with the wolves. You've got to dive into the ocean and fight with the sharks. Or just treat yourself to a delicious hot fudge sundae........ with nuts. - Jack Black
RE: Open an existing Read Only Excel document
It spawned the following idea however.
CODE
Dim xlDummy as Object
Dim xlApp as Object
Dim xlWkbkDummy as Object
Dim ObjWorksheet As Object
'opening a workbook twice for ReadOnly trickery
Set xlDummy = CreateObject("Excel.Application")
Set xlApp = CreateObject("Excel.Application")
xlDummy.DisplayAlerts = False
xlApp.DisplayAlerts = False
Set xlWkbkDummy = xlDummy.Workbooks.Open ("C:\test.xls")
Set ObjWorkbook = xlApp.Workbooks.Open ("C:\test.xls")
'close the first wkbk so only the ReadOnly copy is available to user
xlDummy.quit
Set xlDummy = Nothing
Set xlWkbkDummy = Nothing
Set objWorksheet = xlApp.Sheets("sheet1")
'show ReadOnly wkbk
xlApp.Visible = True
'Set shSheet = Worksheets("Sheet1")
End Sub
Sometimes you gotta leave your zone of safety. You have to manufacture Inspirado. You gotta get out of the apartment. You've got to run with the wolves. You've got to dive into the ocean and fight with the sharks. Or just treat yourself to a delicious hot fudge sundae........ with nuts. - Jack Black
RE: Open an existing Read Only Excel document
This is a simple right click on the file choose properties and check the read only box.
Sometimes you gotta leave your zone of safety. You have to manufacture Inspirado. You gotta get out of the apartment. You've got to run with the wolves. You've got to dive into the ocean and fight with the sharks. Or just treat yourself to a delicious hot fudge sundae........ with nuts. - Jack Black