+ Reply to Thread
Results 1 to 10 of 10

Second time running program and it is read only

  1. #1
    Registered User
    Join Date
    02-18-2006
    Location
    WV
    MS-Off Ver
    2003,2007,2010
    Posts
    69

    Second time running program and it is read only

    I run the below code from ms access to print and change a few dates etc of an excel workbook and then close. What's happening is after running the code maybe I want to open the excel workbook but I get greeted with a its locked and in read only mode. I cant figure out why. When I run the code excel pops up in task manager as running and then closes when done.

    What in the code is causing this? I just want to save and close



    Please Login or Register  to view this content.

  2. #2
    Forum Contributor GWteB's Avatar
    Join Date
    12-13-2021
    Location
    GMT +1
    MS-Off Ver
    2013
    Posts
    136

    Re: Second time running program and it is read only

    This behaviour is caused by not closing your workbook. You're not being warned about that, since the Excel instance isn't visible on your screen.
    Try replacing this line in your code ...
    Please Login or Register  to view this content.
    with these two lines:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-18-2006
    Location
    WV
    MS-Off Ver
    2003,2007,2010
    Posts
    69

    Re: Second time running program and it is read only

    Ok I think I might have it.... I changed the top portion of the code to the below and that worked I also used your modification as well. Thanks....

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    02-18-2006
    Location
    WV
    MS-Off Ver
    2003,2007,2010
    Posts
    69

    Re: Second time running program and it is read only

    Well I jumped the gun on it being fixed. I printed it the first time and all good then I test printed it a second time and at the end of the print I got a message asking if I wanted to save the excel workbook, I said yes and closed it. Then I tried to open the excel workbook and it said it was read only.... Just like before

  5. #5
    Forum Contributor GWteB's Avatar
    Join Date
    12-13-2021
    Location
    GMT +1
    MS-Off Ver
    2013
    Posts
    136

    Re: Second time running program and it is read only

    I noticed that you're opening a macro enabled workbook with your code. In case this workbook contains code that intercepts some events, especially the BeforeSave, AfterSave & BeforeClose events, then that code could be interfering with yours.

  6. #6
    Registered User
    Join Date
    02-18-2006
    Location
    WV
    MS-Off Ver
    2003,2007,2010
    Posts
    69

    Re: Second time running program and it is read only

    Yes the excel workbook is macro enabled but the only code I have is:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    ActiveWorkbook.Close SaveChanges:=True
    End Sub

    I thought that would help by saving it when this all came about..... I cant work on it until Monday.
    Last edited by oxicottin; 12-17-2021 at 02:20 AM.

  7. #7
    Forum Contributor GWteB's Avatar
    Join Date
    12-13-2021
    Location
    GMT +1
    MS-Off Ver
    2013
    Posts
    136

    Re: Second time running program and it is read only

    That's redundant code since the before close event takes place on closing the workbook, so why closing it (again), and thereby firing a new before close event?

    This could be a cause of your issue since (as mentioned in my post #2) a workbook needs to be closed properly for Excel to mark the workbook as a "full access" file, as opposed to read-only
    (more specifically, for Excel to delete a hidden and simultaneously created file with a similar name preceded by the characters ~$).
    Using the Save method would then be more obvious than the Close method.

    Furthermore, your code acts on the active workbook, which is not necessarily the same workbook as the workbook in which the before close event occurs.
    So if you still want to play it safe, you should use the code below, although I would recommend not to use it, i.e. get rid of this event handler.

    If you have applied the modification I suggested in my post #2 then you should be fine.
    In case there's no change, let me know.

    Please Login or Register  to view this content.
    Last edited by GWteB; 12-17-2021 at 02:07 PM.

  8. #8
    Registered User
    Join Date
    02-18-2006
    Location
    WV
    MS-Off Ver
    2003,2007,2010
    Posts
    69

    Re: Second time running program and it is read only

    Monday ill give it another go... Thanks!

  9. #9
    Registered User
    Join Date
    02-18-2006
    Location
    WV
    MS-Off Ver
    2003,2007,2010
    Posts
    69

    Re: Second time running program and it is read only

    @GWteB, with the changes you gave it seems to be working correctly and I tried several times this time! I think it was the me.save in the workbook....

    Thanks!

  10. #10
    Forum Contributor GWteB's Avatar
    Join Date
    12-13-2021
    Location
    GMT +1
    MS-Off Ver
    2013
    Posts
    136

    Re: Second time running program and it is read only

    You are welcome and thanks for letting me know.

+ 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. Read Excel program on Cell Phone
    By roehrle in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-23-2012, 07:09 PM
  2. Replies: 1
    Last Post: 07-08-2011, 02:18 AM
  3. Key pressed during program running time
    By WCampos in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-17-2008, 05:31 PM
  4. read excel with a c++ program on Unix
    By [email protected] in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-27-2006, 05:15 PM
  5. [SOLVED] keeping a running time for tv program
    By Jim in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 04-24-2006, 01:25 PM
  6. [SOLVED] Read only Excel Program
    By Casual in forum Excel General
    Replies: 3
    Last Post: 03-10-2006, 07:20 PM
  7. how can make the program read the word
    By frsm in forum Excel General
    Replies: 0
    Last Post: 03-06-2006, 12:03 PM
  8. [SOLVED] Re: PLEASE READ IF YOU PROGRAM: Help Continue Visual Basic
    By Lonnie M. in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-01-2005, 05:10 PM

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