+ Reply to Thread
Results 1 to 8 of 8

Force read only / acquire write permission

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-26-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    173

    Thumbs up Force read only / acquire write permission

    Hello Excelforum!

    I have a collection of macros that I share with other computers on my network. The macros is shared on a network drive accessible to both computers stored at Z:\Excel Macros\smpitaReports.xlam as an Add-in file. I am constantly updating and tweaking the macros but whoever is the first person to open their Excel gets write permission and the rest of us get read permission. I need to figure out a way to control this without changing network/filesystem permissions.

    I figure the best way to do this is to make everyone open the file as read only by default and then when I need to make updates to it, run a macro to acquire write access. Can this be done in VBA? I have access to each terminal Excel so I can put in a startup macro to check for write access and then drop to read only if write access is found. I started to try to piece it together from searching the internet but I'm hitting a brickwall at the start. This is as far as I've gotten which is a failed attempt at a basic check for read only access that gives me an "Object Required" error.

    Sub TakeControl()
    
    Dim MyAddin
    MyAddin = "Z:\Excel Macros\smpitaReports.xlam"
        
        If MyAddin.ReadOnly Then
            MsgBox "Read only access"
        Else
            MsgBox "Write access"
        End If
    End Sub
    Is there an easier way to do this? Ideas are welcome.

    Thank you for your time!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,311

    Re: Force read only / acquire write permission

    Untested, but try:

    Sub TakeControl()
    
    Dim MyAddin
    Set MyAddin = workbooks.open("Z:\Excel Macros\smpitaReports.xlam")
        
        If MyAddin.ReadOnly Then
            MsgBox "Read only access"
        Else
            MsgBox "Write access"
        End If
    End Sub
    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    02-26-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    173

    Re: Force read only / acquire write permission

    Hello TMS!

    Thank you for your attention to my thread! I get the error "This workbook is currently referenced by another workbook and cannot be closed" on the line
    Set MyAddin = Workbooks.Open("Z:\Excel Macros\smpitaReports.xlam")

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,311

    Re: Force read only / acquire write permission

    Looks like you got your object but it's in use.

    Sorry, I don't know what else to suggest.

  5. #5
    Forum Contributor
    Join Date
    02-26-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    173

    Re: Force read only / acquire write permission

    Thanks TMS!

  6. #6
    Forum Contributor
    Join Date
    02-26-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    173

    Re: Force read only / acquire write permission

    With more research, I have decided to change my deployment method. I mostly followed the guidelines on another site, keeping the development copy on my computer and pushing a read only copy to the network share for others to use. I used the following code template:
    Sub DeployAddIn()
    'Author       : Ken Puls (www.excelguru.ca)
    'Macro Purpose: To deploy finished/updated add-in to a network
    '               location as a read only file
        Dim strAddinDevelopmentPath As String
        Dim strAddinPublicPath As String
    
        'Set development and public paths
        strAddinDevelopmentPath = ThisWorkbook.Path & Application.PathSeparator
        strAddinPublicPath  = "F:\Addins" & Application.PathSeparator
    
        'Turn off alert regarding overwriting existing files
        Application.DisplayAlerts = False
    
        'Save the add-in
        With ThisWorkbook
            'Save to ensure work is okay in case of a crash
            .Save
    
            'Save read only copy to the network (remove read only property
            'save the file and reapply the read only status)
            On Error Resume Next
            SetAttr strAddinPublicPath & .Name, vbNormal
            On Error Goto 0
            .SaveCopyAs Filename:=strAddinPublicPath  & .Name
            SetAttr strAddinPublicPath & .Name, vbReadOnly
        End With
    
        'Resume alerts
        Application.DisplayAlerts = True
    End Sub

  7. #7
    Forum Contributor
    Join Date
    02-26-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    173

    Re: Force read only / acquire write permission

    Closing thread and marking as solved.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,311

    Re: Force read only / acquire write permission

    Excellent! Thanks for sharing your solution. Very much appreciated.

    Thanks for the rep.

    Regards, TMS

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 07-24-2014, 08:59 PM
  2. [SOLVED] Checking to see if a file has been opened in Read/Write or Read Only
    By brokenbiscuits in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-13-2014, 09:16 AM
  3. Replies: 2
    Last Post: 02-11-2013, 08:44 AM
  4. Set permission to change and read-only file in dropbox
    By ioncila in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-12-2012, 06:01 AM
  5. How can a file be converted from Read-Only to Read/Write
    By Jim in Apopka in forum Excel General
    Replies: 2
    Last Post: 11-19-2005, 01:00 PM

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1