+ Reply to Thread
Results 1 to 3 of 3

Beforeclose problem when file is opened as Read only

Hybrid View

  1. #1
    Registered User
    Join Date
    02-02-2010
    Location
    Belgium
    MS-Off Ver
    Excel 2003
    Posts
    47

    Beforeclose problem when file is opened as Read only

    Hello,

    When my workbook is opened as read only with macro's enabled the VBA gives an error when I wan't to close the workbook?

    As you can see the beforeclose saves a copy to a specific location and a backup.

    can this be solved by making it skip the code when the workbook is opened in read only mode??

    Option Explicit
    
    Private Sub Workbook_Activate()
        ShowMenu
    End Sub
    'Skip this when read only or something to prevent this code from running in read onlymode
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        RemoveMenu
        'ThisWorkbook.SaveCopyAs "\\BER...1\Shared\" & "UT_BORDEN_" & Format(Now(), "DD.MMM.YYYY_hh.mm.ss") & ".xls"
           ThisWorkbook.SaveCopyAs "\\BER...1\Shared\....xls"
                ThisWorkbook.Save
    End Sub
    
    Private Sub Workbook_Deactivate()
        HideMenu
    End Sub
    
    Private Sub Workbook_Open()
        AddMenu
    End Sub
    Last edited by Bluewhistler; 07-12-2010 at 04:16 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,280

    Re: Beforeclose problem when file is opened as Read only

    SaveCopyAs should be fine, I would think, but the ThisWorkbook.Save will fail. Try:
    If Not ThisWorkbook.Readonly then ThisWorkbook.Save
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    02-02-2010
    Location
    Belgium
    MS-Off Ver
    Excel 2003
    Posts
    47

    Re: Beforeclose problem when file is opened as Read only

    Quote Originally Posted by romperstomper View Post
    SaveCopyAs should be fine, I would think, but the ThisWorkbook.Save will fail. Try:
    If Not ThisWorkbook.Readonly then ThisWorkbook.Save
    BullsEye!
    many thx

+ 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