+ Reply to Thread
Results 1 to 10 of 10

VBA Next Workbook If This Workbook is Macro Wookbook

  1. #1
    Registered User
    Join Date
    03-27-2013
    Location
    Wiltshire, England
    MS-Off Ver
    Excel 2007
    Posts
    75

    VBA Next Workbook If This Workbook is Macro Wookbook

    I require some VBA code so if the person executes the macro while the macro workbook is the active workbook then the macro moves to the next open workbook.

    I thought something like the following:

    Dim WB As Workbook
    For Each WB in Workbooks
    If WB Is ThisWorkbook Then Next WB

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: VBA Next Workbook If This Workbook is Macro Wookbook

    Hello
    Can you explain more and upload sample of your workbooks so as to get the issue? How many workbooks will be open? Are those workbook with specific names which have specific sequence? What determine the next workbook for you or it is any workbook?
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Registered User
    Join Date
    03-27-2013
    Location
    Wiltshire, England
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: VBA Next Workbook If This Workbook is Macro Wookbook

    Hello

    There will be two other workbooks open when the macro is executed.
    They will not have specific names, they are likely to have different names each time.
    No specific sequence is required.
    The next workbook can be any other open workbook

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: VBA Next Workbook If This Workbook is Macro Wookbook

    So what will you do with each open workbook?

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: VBA Next Workbook If This Workbook is Macro Wookbook

    As start point you can loop through the open workbooks like that
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    03-27-2013
    Location
    Wiltshire, England
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: VBA Next Workbook If This Workbook is Macro Wookbook

    The two other open workbooks will contain employee payroll data and I will manipulate the data with a macro that is already written.
    As the macro is sometimes run by other work colleagues who are not so technical with excel, I want to add some code at the beginning, so the macro moves to any other open workbook, if they start the macro from within the macro workbook itself.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA Next Workbook If This Workbook is Macro Wookbook

    What do you mean by the 'next open' workbook?
    If posting code please use code tags, see here.

  8. #8
    Registered User
    Join Date
    03-27-2013
    Location
    Wiltshire, England
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: VBA Next Workbook If This Workbook is Macro Wookbook

    Ok, lets say we have three open workbook files called A, B and C.
    A and B are the working files and file C is the macro file.
    If the person executing the macro has file C as the active file when the macro starts I want the macro to move to either file A or file B.
    I can't refer to exact file names in the macro, because files A and B will have different names each time.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA Next Workbook If This Workbook is Macro Wookbook

    Is the code meant to be run on all open workbooks apart from the 'macro' workbook?

  10. #10
    Registered User
    Join Date
    03-27-2013
    Location
    Wiltshire, England
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: VBA Next Workbook If This Workbook is Macro Wookbook

    Hi Norie, yes it would be on all open workbooks.

    I am looking for some vba, so when the macro starts, if the user already has file A or file B as the active workbook we are fine. If the user starts the macro with the macro workbook as the active workbook then the code makes workbook A or workbook B the acti e workbook.

    So the vba I need is, if we are on workbook A or workbook B do nothing. If we are on workbook C (the macro workbook) then make workbook A or workbook B the active workbook. I don't mind which.

+ 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. [SOLVED] VBA Macro pull a certain cell in closed workbook and copy/paste into current workbook
    By Hoover5896 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-08-2017, 01:36 AM
  2. [SOLVED] VBA to open new workbook and run macro from new workbook, which closes old workbook
    By Rerock in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-26-2014, 10:45 AM
  3. [SOLVED] Macro to find data in source workbook and copy paste to target workbook
    By D.Lovell in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-23-2014, 06:21 AM
  4. Replies: 4
    Last Post: 03-06-2014, 07:49 PM
  5. [SOLVED] Save the split the workbook file type as Excel Binary Workbook From Run Macro
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-25-2013, 05:09 AM
  6. Replies: 0
    Last Post: 07-27-2011, 09:48 PM
  7. Closing master wookbook from another workbook
    By zplugger in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-08-2011, 01:07 PM

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