Results 1 to 2 of 2

Thread: Workbook A(Sheet 1) and Workbook B(Sheet 2) are opened or not

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    13

    Workbook A(Sheet 1) and Workbook B(Sheet 2) are opened or not

    Hi all,please help...

    I want to write a VB-Excel macro , which will prompt a messgae box "Both W.B opened" if this macro finds Workbook A(Sheet 1) and Workbook B(Sheet 2) opened else msgbox "W.B NOT opened"

    Can anyone write it for me???

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Workbook A(Sheet 1) and Workbook B(Sheet 2) are opened or not

    vb Code:
    1. for wb = 1 to workbooks.count
    2.    if wb.name = "workbookA.xls" then
    3.        for each sh in wb.sheets
    4.           if sh.name = "Sheet1" then a = true: exit for
    5.        next
    6.    elseif  wb.name = "workbookB.xls" then
    7.        for each sh in wb.sheets
    8.           if sh.name = "Sheet2" then b = true: exit for
    9.        next  
    10.    end if
    11. next
    12. if a and b then
    13.   msgbox "both open"
    14. else
    15.   msgbox "both not open
    16. end if
    names of workbooks and sheets need to be exact and case sensitve
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width