Results 1 to 14 of 14

Thread: Excel VBA - OLEObject Error When WorkBook Is Set As "Shared"

Threaded View

  1. #2
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Excel VBA - OLEObject Error When WorkBook Is Set As "Shared"

    I think with a shared workbook, you can only modify data but you cannot modify any structure or object.

    To prevent user uses the Excel built-in Save button or menu you can do it like this:

    In ThisWorkbook code module:
    Code:
    Option Explicit
    
    Public bAllowSave As Boolean
    
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
       If bAllowSave = False Then
          MsgBox "Please Click button [Save HFR] to Save the workbook.", _
                 vbExclamation, "Cannot Save Now"
          Cancel = True
       End If
    End Sub
    In the code module of the sheet that contains the button [cmdSaveHFR] :
    Code:
    Option Explicit
    
    Private Sub cmdSaveHFR_Click()
       ThisWorkbook.bAllowSave = True
       
       '-- your extra code before saving here
       
       ThisWorkbook.Save
       ThisWorkbook.bAllowSave = False
    End Sub
    However, remember that those won't prevent users to disable/stop macros then save with Excel built-in Save function.
    Last edited by anhn; Apr 13th, 2009 at 09:44 AM.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width