Results 1 to 8 of 8

Thread: How to make Excel VBA Read Only

  1. #1
    Join Date
    Jan 2009
    Posts
    74

    How to make Excel VBA Read Only

    Hi friends,

    I have created a workbook in excel and i don't want anyone to make any changes in it, they should only be able to ready those Excel file and cannot write in that file.In short i need to have my Excel VBA in read only format.Can anyone help me out with this issue.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How to make Excel VBA Read Only

    The ReadOnly property will not allow you to set the property it's only being used to check whether workbook is ReadOnly or not.For making your workbook Readyonly with all users you need to use SaveAs Method.

  3. #3
    Join Date
    Dec 2008
    Posts
    164

    Re: How to make Excel VBA Read Only

    Try to use the code for making you Excel workbook ReadOnly


    Code:
    Sub Workbook_Open
       If Environ("Username") = "Administrator" or Environ("Username") = "XYZ"    then
          Workbooks.Open "c:\demo.xls"
       Else
          Workbooks.Open "c:\demo.xls", , True
       End If
    End Sub

  4. #4
    Join Date
    Jan 2009
    Posts
    74

    Re: How to make Excel VBA Read Only

    I have tried to use the above code for Excel but it's says me do you want to reopen the Excel file which should not happen i should be able to open workbook as ReadOnly at first time only.

  5. #5
    Join Date
    Dec 2008
    Posts
    101

    Re: How to make Excel VBA Read Only

    Try to use the below code for making you Excel file in ReadOnly mode.


    Code:
    Private Sub Workbook_Open()
       Application.DisplayAlerts = False
       If Environ("Username") = "Administrator" or Environ("Username") = "XYZ" then
          MsgBox "It's in Edit mode"
          Workbooks.Open "d:\Example.xls"
       Else
          MsgBox "It's in Read Only mode"
          Workbooks.Open "d:\Example.xls", , True
       End If
       Application.DisplayAlerts = True
    End Sub

  6. #6
    Join Date
    May 2009
    Posts
    1

    Re: How to make Excel VBA Read Only

    Hi Amit,

    How would I modify the code if I want all users to open the workbook in read-only but have a macro that will run automatically everytime the workbook is opened? This macro will need to update some fields, so the workbook should be in write mode, right? But the user has it opened it read-only?

    Please share suggest possible solutions, thanks!

  7. #7
    Join Date
    Dec 2012
    Posts
    1

    Re: How to make Excel VBA Read Only

    Dear All,
    Kindly, assist me to look into this code; it throws a compile error "syntax error"

    Sub SaveFileReadOnly()
    '
    ' SaveFileReadOnly Macro
    '
    On Error Resume Next

    Call C:\Users\Adam.abc\Desktop\SANPCODES.xlsx

    ActiveWorkbook.SaveAs Filename:= _
    "C:\Users\Adam.abc\Desktop\SANPCODES.xlsx", FileFormat:= _
    xlOpenXMLWorkbook, CreateBackup:=False

    SetAttr "C:\Users\Adam.abc\Desktop\SANPCODES.xlsx", vbReadOnly
    ActiveWorkbook.Close

    End Sub

  8. #8
    Join Date
    Dec 2007
    Posts
    2,291

    Re: How to make Excel VBA Read Only

    Quote Originally Posted by RoiJoy View Post
    Dear All,
    Kindly, assist me to look into this code; it throws a compile error "syntax error"

    Sub SaveFileReadOnly()
    '
    ' SaveFileReadOnly Macro
    '
    On Error Resume Next

    Call C:\Users\Adam.abc\Desktop\SANPCODES.xlsx

    ActiveWorkbook.SaveAs Filename:= _
    "C:\Users\Adam.abc\Desktop\SANPCODES.xlsx", FileFormat:= _
    xlOpenXMLWorkbook, CreateBackup:=False

    SetAttr "C:\Users\Adam.abc\Desktop\SANPCODES.xlsx", vbReadOnly
    ActiveWorkbook.Close

    End Sub
    I dont know what are you trying to ask, but you can test the ReadOnly property of the workbook before trying to save. You can also use the below code to set the ReadOnly property:

    SetAttr pathname, attributes

    To set ReadOnly=True
    SetAttr "C:\Blank.xls", vbReadOnly

    To set ReadOnly=False
    SetAttr "C:\Blank.xls", vbNormal

Similar Threads

  1. How to make iTunes read my disc instead of grace note
    By Shantiprakash in forum Portable Devices
    Replies: 3
    Last Post: 23-02-2011, 10:55 AM
  2. How to read Excel (xls file) From C#
    By KornFlexia in forum MS Office Support
    Replies: 3
    Last Post: 16-12-2010, 08:24 AM
  3. Word & Excel files all Read Only
    By Robbin M in forum MS Office Support
    Replies: 3
    Last Post: 22-10-2010, 09:51 AM
  4. How to read and write Excel files in PHP ?
    By Sudra in forum Software Development
    Replies: 3
    Last Post: 06-05-2009, 05:18 PM
  5. Read information from Excel to VB
    By Jateen in forum Software Development
    Replies: 2
    Last Post: 06-01-2009, 03:28 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,563,952.68125 seconds with 17 queries