Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Excel Read Only from Access 2000 1

Status
Not open for further replies.

SiberBob

Programmer
Aug 28, 2002
107
US
I have some code (thanks to RoyVidar) that opens a word document read only. Can someone tell me if there is a way to open an excel file read only without having to set each individual file as read only?

 
Have a look at the 3rd argument of the Workbooks.Open method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Worked like a charm!

I was just guessing when I tried to modify RoyVidar's code from opening Documents to opening Spreadsheets and I should have used Workbooks...

Here is the code I ended up with that works to open excel documents read only... This actually just a minor modification on Roy Vidar's code and I can't take any credit for it... Thanks to both of you.


Code:
Public Sub OpenExcelReadOnly(strDoc As Variant)
Dim wapp As Object
Dim wdoc As Object
On Error Resume Next
    Set wapp = GetObject(, "excel.application")
        If Err.Number <> 0 Then
          Err.Clear
          Set wapp = CreateObject("excel.application")
          If Err.Number <> 0 Then
            Exit Sub
          End If
        End If
On Error GoTo ERR_OpenExcelReadOnly
Set wdoc = wapp.Workbooks.Open(strDoc, , True)
    wapp.Visible = True
    Set wdoc = Nothing
    Set wapp = Nothing
ExitingSub:
Exit Sub
ERR_OpenExcelReadOnly:
[green]        '   BugReport is my custom function to mail the programmer details on the errors encountered.[/green]
    BugReport Err.Description, Err.Source, "Public Sub OpenExcelReadOnly(strDoc As Variant)" 
    Err.Clear
    GoTo ExitingSub
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top