+ Reply to Thread
Results 1 to 5 of 5

How to determine the name of a read-only file (activeworkbook.name causes error 91)

  1. #1
    Registered User
    Join Date
    08-30-2012
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    83

    How to determine the name of a read-only file (activeworkbook.name causes error 91)

    Hi There,

    I have a rather large and cumbersome program. I have two questions!

    Version:
    Excel 2016

    The problem:
    When the workbook containing my program is open (we'll call it "Program Workbook"), if I open any other file in Excel, it triggers the CALCULATE event from ThisWorkbook sheet of the "Program Workbook".
    Please Login or Register  to view this content.
    I regularly need to open (.xml) files from emails. When I open these files, they are opened as Read-only.

    in the CALCULATE event, I use the reference
    Please Login or Register  to view this content.
    Trying to execute this line is producing the error message:
    vba excel run-time error '91':
    Object variable or With block variable not set.
    I want to avoid this so that I don't need to shut down the Program Workbook every time I wish to open a read-only sheet (which is regularly!). I also don't wish to copy the file from the email to the desktop and then open it.
    (I am effectively using this to ensure that the "Program Workbook" is the active workbook (by checking if activeworkbook.name = thisworkbook.name)
    Please Login or Register  to view this content.
    So the question is,
    Can I capture the name of the read-only file that has just opened by a different method, or can I check to see if the activeworkbook is read-only to avoid the above error?
    (checking
    Please Login or Register  to view this content.
    produces the same error).
    Alternatively, can I avoid the error by a different check to protect this line from fateful execution?!

    I wonder as the file is trying to open, perhaps there is no activeworkbook at that moment?


    As a secondary question, I wouldn't have thought that opening a different workbook would have triggered the CALCULATE event on the "Program Workbook" ThisWorkbook sheet. Should this be the case? If not, what could be triggering it? There is nothing in "Personal.xlsb" ThisWorkbook sheet.


    I would appreciate any comments that might guide me in the correct direction!



    additional info (which I don't think is required, but may throw some light on the subject)

    I need the CALCULATE event in The Program in order to perform an operation on one of the sheets within the workbook.). I have used volatile data (the
    Please Login or Register  to view this content.
    function and also formulae to trigger the CALCULATE event when anything about specific sheets are changed)

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to determine the name of a read-only file (activeworkbook.name causes error 91)

    Hi,

    If you have volatile formulas, opening another workbook will cause them to recalculate, hence your event trigger.

    Are the XML files opening in Protected mode?
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    08-30-2012
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    83

    Re: How to determine the name of a read-only file (activeworkbook.name causes error 91)

    Hi xlnitwit,

    Thanks for your response (and confirmation of answer to Question 2!).

    Yes, when I double click on the file in Outlook, it is opening in [Protected View].
    The file appears with the yellow ribbon(information bar) at the top of the workbook, "Protected View Be careful-email attachments can contain viruses. Unless you need to edit, it's safer to stay in Protected View.".
    In the ribbon bar, it includes the button ("Enable Editing") which can be clicked (or not).

    What is the best way to cater for this in the macro and avoid an error?

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to determine the name of a read-only file (activeworkbook.name causes error 91)

    I cannot currently test this but perhaps something like this
    Please Login or Register  to view this content.
    which should prevent attempting to test the activeworkbook when a protected window is active.

  5. #5
    Registered User
    Join Date
    08-30-2012
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    83

    Re: How to determine the name of a read-only file (activeworkbook.name causes error 91)

    Please Login or Register  to view this content.
    Is exactly what I was after - Thank you xlnitwit !!



    (SOLVED)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Using Variables IE Date to determine which file/tab to read from?
    By awaken88 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-27-2012, 05:57 PM
  2. Replies: 1
    Last Post: 01-18-2012, 06:59 PM
  3. Replies: 1
    Last Post: 01-18-2012, 06:57 PM
  4. Error: Unable to read file
    By whitepaw in forum Excel General
    Replies: 1
    Last Post: 08-31-2008, 07:07 AM
  5. Replies: 5
    Last Post: 06-05-2006, 08:30 AM
  6. Replies: 0
    Last Post: 10-12-2005, 12:05 PM
  7. Excel File - Read Only Error
    By ritu in forum Excel General
    Replies: 3
    Last Post: 07-20-2005, 03:05 AM
  8. [SOLVED] Read txt file for input error handler
    By Chirs in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-30-2005, 08:05 AM

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