+ Reply to Thread
Results 1 to 3 of 3

Disable Macro if Read Only

  1. #1
    Registered User
    Join Date
    01-19-2010
    Location
    Surrey, UK
    MS-Off Ver
    Excel 2003
    Posts
    2

    Disable Macro if Read Only

    I've tried searching for a solution to this, but as yet not one found.

    Is there a way to disable the below macros if the file is opened in read only? i.e. only run them when the file is opened as write and read?

    Here's the code I'm using at the minute:


    Module 1

    Dim DownTime As Date

    Sub SetTime()
    DownTime = Now + TimeValue("00:05:00") 'change time as needed
    Application.OnTime DownTime, "ShutDown"
    End Sub

    Sub ShutDown()
    ThisWorkbook.Save
    ThisWorkbook.Close
    End Sub

    Sub Disable()
    On Error Resume Next
    Application.OnTime EarliestTime:=DownTime, Procedure:="ShutDown", Schedule:=False
    End Sub


    ThisWorkbook

    Private Sub Workbook_Open()
    MsgBox " Welcome to Master Sales" & vbCrLf & _
    " This workbook will auto-close after 5 minutes of inactivity"
    Call SetTime
    End Sub

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Call Disable
    End Sub

    Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
    Call Disable
    Call SetTime
    End Sub

    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)
    Call Disable
    Call SetTime
    End Sub

    Thanks in advance!

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Disable Macro if Read Only

    I think if you pop something like this at the start of each sub it should work:

    Please Login or Register  to view this content.
    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    01-19-2010
    Location
    Surrey, UK
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Disable Macro if Read Only

    Magic, thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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