Open as read only from same folder - on any PC

  • Hello Wizards,


    Code below works on my PC – it opens file ABCD.xlsm as read only from the same folder where I have the file with this code in it, then closes this workbook.
    Problem is that when I open this workbook on another person’s PC, gives error – can’t find .\ABCD.xlsm
    When I got rid of that dot before the backslash I got same error even on my PC…

    Code
    [I]Private Sub Workbook_Open()[/I]
    [I]Workbooks.Open Filename:=".\ABCD.xlsm", ReadOnly:=True[/I]
    [I]ThisWorkbook.Close[/I]
    [I]End Sub[/I]
  • Try this, the workbook ABCD must be in the same folder as the one with the code


    Code
    Option Explicit
    
    
    Private Sub Workbook_Open()
    Workbooks.Open Filename:=ThisWorkbook.Path & Application.PathSeparator & "ABCD.xlsm", ReadOnly:=True
    ThisWorkbook.Close
    End Sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!