Check to see if 2 workbooks open and if yes exit sub

  • Hi All, I was hoping someone might be able to help with the following issue. I enter info into workbook1 and then run a macro to update workbook2 and workbook3. The code below works fine in terms of the updating but I am struggling to find a way to handle the problems if workbook2 or workbook3 is open.


    I was hoping to check if workbook2 or workbook3 is open and then simply exit the sub. Thank you in anticipation of any help that can be provided. Best regards, Jay.


  • Re: Check to see if 2 workbooks open and if yes exit sub



    shorter


  • Re: Check to see if 2 workbooks open and if yes exit sub


    Hi, Jay,


    why exit the sub? In use by you or any other user? If by you/user in the same instance you may like to try


    Ciao,
    Holger

  • Re: Check to see if 2 workbooks open and if yes exit sub


    Keep it simple


    Code
    sub M_snb()
        If Not Evaluate("isref('[workbooks2.xls]sheet1'!A1)") Then Workbooks.Open "C:\Users\Desktop\Workbooks2.xls"
        If Not Evaluate("isref('[workbooks3.xlsx]sheet1'!A1)") Then Workbooks.Open "C:\Users\Desktop\Workbooks3.xlsx"
    End Sub
  • Re: Check to see if 2 workbooks open and if yes exit sub


    Hi Gents... Patel, HaHoBe & snb, thanks very much for taking the time to reply, I really appreciate the help.
    HaHoBe, I wanted to exit the sub because I am trying to write info to other workbooks and there is a chance that another user may have them open. I am a vba amateur so be gentle :)


    I have had a good play today with examples you all provided but snb's example was the only one I was able to manipulate to do as I wanted, probably down to lack of skill, ha. It isn't pretty but it seems to do what is required. Below is the finished macro that updates workbooks 2 & 3 with info from workbook 1. If either workbook 2 or 3 is already open then the user gets an alert.


    Again, thank you all for your help.. Ozgrid rules, Jay


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!