+ Reply to Thread
Results 1 to 6 of 6

How to edit a file that is already open by that same user, without re-opening it

  1. #1
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    How to edit a file that is already open by that same user, without re-opening it

    Greetings,


    As always, thanks in advance for any replies.

    I have an Excel file with macro code which opens a second Excel file and manipulates the data inside by entering data in certain cells. The code is working fine.

    However, at times that second file is already open. (Only by that same user, I should add, right there on the same laptop.) When that second file is already open, I'm getting an Excel warning that saying that yes, the file is already open and re-opening will cause any changes to be discarded.

    What I'd like to do in that case is NOT re-open that second file, but instead just continue to allow the macro to work by editing it, and entering additional data in some of the worksheets and cells within the file.

    I can't seem to get that to work. I don't know how to reference that workbook that's already open, without opening it again.


    This statement opens the second file just fine:

    Set my_wkb = Workbooks.Open(Second_Filename$)


    And note that I do have code to test to see if that second file is already open, and that's working fine too. But if it is already open, how do I allow my macro to continue to edit it? Do I really have to have the user save that second file, close it, and only then run the macro that will re-open and edit it? So far that's what they've been doing.
    Last edited by Ed_Collins; 10-25-2018 at 07:08 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: How to edit a file that is already open by that same user, without re-opening it

    If it's already open, and you have code to test for that, just skip the open. So, test if it's open; if it is, skip the open .... that is, don't do anything; if it isn't, execute the open workbook code
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How to edit a file that is already open by that same user, without re-opening it

    Something like this:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    Re: How to edit a file that is already open by that same user, without re-opening it

    TMS, thank you for replying.


    Yes, I tried that, but I'm getting an Object Variable or With block variable not set error message.

    And I'm getting this error when it's first referencing that file. (In this case I'm first simply unprotecting a sheet.)

    my_wkb.Sheets("My Tab Name").Unprotect


    And sure, it should crash, because I haven't declared what my_wkb is in this case. And yet when I tried to do so, via this statement:

    Set my_wkb = Workbooks(Second_Filename$)

    (which replaced this statement, which worked: Set my_wkb = Workbooks.Open(Second_Filename$) )

    I'm getting a subscript out of range error message.

    So I just need to figure out how to reference that second file, how to properly declare my my_wkb variable, to a file that is already open, that the macro didn't open. I can't figure out how to do that.

  5. #5
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    Re: How to edit a file that is already open by that same user, without re-opening it

    I figured it out, from a forum post at another website.

    If the file is already open, you must set your wkb variable WITHOUT the full path. (When I was opening it, I was, of course, using the full path.)

    For example, instead of this:

    set wkb = workbooks("C:\full_path\secondary folder\name of file.xls")

    you must instead just do this:

    set wkb = workbooks("name of file.xls")


    Doing that fixed everything and it is now doing exactly what I wanted it to do. (Thank you to someone call L42 who mentioned this as a solution over at StackOverflow)

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: How to edit a file that is already open by that same user, without re-opening it

    You're welcome.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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. Replies: 8
    Last Post: 02-19-2018, 10:03 AM
  2. VBA edit help - copy data from an excel without opening the file first
    By TollemG in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-26-2017, 12:59 PM
  3. open, edit, and save a word document based on user response in excel 2010 VBA
    By cmccabe in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-19-2016, 03:13 PM
  4. Replies: 1
    Last Post: 02-02-2014, 08:04 PM
  5. Replies: 12
    Last Post: 06-07-2011, 04:17 AM
  6. Opening a workbook already open by another user
    By KASM in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-24-2010, 06:47 AM
  7. [SOLVED] 2 users open same file and both can edit/change the file
    By RANDY in forum Excel General
    Replies: 1
    Last Post: 01-24-2006, 12: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