Closed Thread
Results 1 to 12 of 12

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

  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 :

    Please Login or Register  to view this content.
    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 ?

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by eawyne; 05-24-2023 at 08:02 AM.

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Opening file in Read Only with VBA and code already existing

    Hi there,

    The following approach might do what you need.

    Password-protect the master workbook (password known only to yourself, e.g. ZZZ).

    Provide Users with a loader workbook which opens the master workbook in read-only mode. The loader workbook is stored in the same folder as the master workbook.

    If Users try to open the master workbook directly they will be asked to insert a password (which they will not have).

    The loader workbook contains the following code in the VBA CodeModule of ThisWorkbook:

    Please Login or Register  to view this content.
    The highlighted values may be altered to suit your requirements.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files
    Last edited by Greg M; 05-17-2023 at 08:28 PM.

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

    Re: Opening file in Read Only with VBA and code already existing

    Thanks for the input I'll try this on monday as I have a long week-end, but I still wanted to acknowledge your message !

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Opening file in Read Only with VBA and code already existing

    Hi again,

    Thanks for that - I look forward to your feedback on Monday.

    Have a good weekend!

    Greg M

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

    Re: Opening file in Read Only with VBA and code already existing

    Hi Greg,

    it works fine ! There's a tiny typo here (should be Filename), you might want to edit your original reply ^^ :

    Please Login or Register  to view this content.
    I'll tinker a bit around, to auto-close the Loader file. I will eventually create more dashboards for different services, and I guess I could adapt the Open condition to different buttons instead.

    Does this have to have Loader and Master in the same folder, or can it include a target folder ? It's not that important, as I can still use shortcuts to lead to the Loader, but I'm curious. (I will try on my own in the meantime ; I need to change the Me. variable)

    But thanks already for your help ! This opens a whole lot of options for me !
    Last edited by eawyne; 05-22-2023 at 08:56 AM.

  6. #6
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Opening file in Read Only with VBA and code already existing

    Hi again,

    Many thanks for your feedback and also for the Reputation increase - much appreciated!

    You're welcome - glad I was able to help.



    Please Login or Register  to view this content.
    There's a tiny typo here (should be Filename), you might want to edit your original reply ^^

    Nope - no typo! See the line below

    Please Login or Register  to view this content.

    Your other question:


    Does this have to have Loader and Master in the same folder, or can it include a target folder ?

    The Master workbook can be located anywhere as long as the Loader workbook "knows" where to locate it.


    Best regards,

    Greg M

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

    Re: Opening file in Read Only with VBA and code already existing

    Quote Originally Posted by Greg M View Post

    Nope - no typo! See the line below

    Please Login or Register  to view this content.
    Holy moly, I have no idea why I said that ^^' I had tested it, so why would it've worked if there was a typo... Anyway, thanks again.

  8. #8
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Opening file in Read Only with VBA and code already existing

    Hi again,

    Thanks for that feedback.

    You're welcome.

    Best regards,

    Greg M

  9. #9
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,224

    Re: Opening file in Read Only with VBA and code already existing

    Please Login or Register  to view this content.
    I conclude that the file is located in a shared folder. If you, as the file administrator, give the file the "Read Only" attribute (at the system level, not in Excel), everyone will open the file in "Read Only" mode. Since everyone who runs the file opens a copy of it, the master file is not locked and can be replaced with a newer version without problems. In my opinion, when we set the file attribute, there is no need for an intermediate file (Loader).
    When opening a file, you can additionally check that the file is NOT in "Read Only" mode. If it would be, you can change its mode (code in ThisWorkbook module):
    Please Login or Register  to view this content.
    Artik

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

    Re: Opening file in Read Only with VBA and code already existing

    Hi Artik,

    thanks for the input ! it works, but I'm confronted with the same problem I had initially, as mentionned in the OP : it interferes with the other code in ThisWorkbook, and not all the menus get hidden (in this case, the formula bar or the cell names still show). I'm not sure if it's related to the code itself or how it's being run...

    As for the master file not being locked, Greg's solution has a password involved, so there's no easy possibility to edit the file anyway. However, it still provides me with a bit of code I could use in other files that don't run much code on file opening

    EDIT : as it is, the Loader File has become a good idea for how my projects will evolve.
    Last edited by eawyne; 05-24-2023 at 07:58 AM.

  11. #11
    Registered User
    Join Date
    04-02-2019
    Location
    ooty
    MS-Off Ver
    7
    Posts
    1

    Re: Opening file in Read Only with VBA and code already existing

    csv batch upload error excels 2013 Debit Credit amount not tallied please answer.

  12. #12
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

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

    @22Anand

    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #1 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

Closed Thread

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