Results 1 to 12 of 12

[Solved] Opening file in Read Only with VBA and code already existing

Threaded View

  1. #1
    Registered User
    Join Date
    11-11-2021
    Location
    France
    MS-Off Ver
    2021
    Posts
    22

    [Solved] Opening file in Read Only with VBA and code already existing

    Hi all,

    I have this workbook used by many people as a dashboard ; when I need to update it, I usually ask they close their files (only a few PCs), but it's going to be expanded, and that's not something I'll be able to do anymore.

    So I tried to force the opening to Read Only, but it isn't handy as it requires a Yes, and I believe it will fly over the head of way too many people. For now, I'll leave it like this, but I tried to go through VBA, with this little bit :

     file_path = "W:\filepath.xlsm"
        Set my_wb = Workbooks.Open(fileName:=file_path, ReadOnly:=True)
    As is, it works, but I have several other code running at start/open of the file, and the application of the Read Only status overrides some of them it appears, specifically the hiding of the ribbons.

    I've tried working around putting the code on Activation, but it didn't work out. How could I integrate it properly ?

    Option Explicit
    
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    
        ThisWorkbook.Saved = True
       
    End Sub
    
    'Cache le ruban ? l'ouverture du Kiosk, ou lorsqu'on met le focus dessus ; cette option ne s'applique qu'? lui.
    Private Sub Workbook_Activate()
    
        Application.ScreenUpdating = False
        Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)"
        Application.DisplayFormulaBar = False
        Application.DisplayStatusBar = Not Application.DisplayStatusBar
        ActiveWindow.DisplayWorkbookTabs = False
        Application.ScreenUpdating = True
    
    End Sub
    
    'Affiche le ruban ? la fermeture du Kiosk, ou lorsqu'on en quitte le focus ; cette option ne s'applique qu'au Kiosk.
    Private Sub Workbook_Deactivate()
    
        Application.ScreenUpdating = False
        Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",True)"
        Application.DisplayFormulaBar = True
        Application.DisplayStatusBar = True
        Application.ScreenUpdating = True
    
     End Sub
    
    Private Sub Workbook_Open()
    
    Dim my_wb As Workbook
    Dim file_path As String
    
        Sheets("Kiosk").Visible = True
        Sheets("Support").Visible = False
        Sheets("Divers").Visible = False
        Sheets("Other").Visible = False
        Sheets("Other2").Visible = False
        Sheets("Templates").Visible = False
        Sheets("addresses").Visible = False
        Sheets("Test").Visible = False
        Sheets("Classified As UnClassified").Visible = False
        Sheets("Other3").Visible = False
        Sheets("Quotes").Visible = False
        Sheets("LinkCheck").Visible = False
        Sheets("Repair").Visible = False
    
        ActiveWindow.Zoom = 85
        
        file_path = "W:\filepath.xlsm"
        Set my_wb = Workbooks.Open(fileName:=file_path, ReadOnly:=True)
        
    End Sub
    Attached Files Attached Files
    Last edited by eawyne; 05-24-2023 at 08:02 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How can I detect in VBA when a workbook is "ready" for user after opening?
    By jsmock in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-28-2021, 09:50 AM
  2. How can I make a ready calculation for this Excel file
    By hotline15 in forum Excel General
    Replies: 1
    Last Post: 02-19-2019, 09:44 AM
  3. Replies: 4
    Last Post: 01-24-2012, 12:52 PM
  4. Opening EXCEL with a specific file opening also
    By HitTheEXCELerator in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-23-2011, 12:51 PM
  5. Opening file message when opening a file from an http address
    By The_Real_MerlinXL in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-26-2010, 12:33 PM
  6. Opening files macro help (forcing directory, opening a tsv file)
    By NukedWhale in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-10-2010, 03:07 PM
  7. [SOLVED] opening an excel file opens a duplicate file of the same file
    By skm in forum Excel General
    Replies: 1
    Last Post: 12-07-2005, 01:55 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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1