+ Reply to Thread
Results 1 to 9 of 9

VB code to control Workbook2 form Workbook1

  1. #1
    Registered User
    Join Date
    09-20-2008
    Location
    France
    Posts
    9

    VB code to control Workbook2 form Workbook1

    Hello,
    I am hoping someone can help me please.


    I am using code associated with Workbook1 to control Workbook2.

    Workbook1 = Bank Transactions1.xlsm
    Workbook2 = Bank Transactions2.xlsm

    These lines of code works :

    Workbooks("Bank Transactions2.xlsm").Worksheets(2).Activate
    Workbooks("Bank Transactions2.xlsm").Worksheets("Transactions").Activate

    But this (which is what I wish to use) does NOT work:

    Workbooks("Bank Transactions2.xlsm").Worksheets("Sheet11").Activate


    Has anyone any idea why not ?

    Notes:
    1) Office 2013
    2) In a Private Sub CommandButton14_Click()
    3) Sheet11 is the "Transactions" tab, and corresponds to the 2nd worksheet along the tabs .....hence Worksheets(2)

    Thanks
    John

  2. #2
    Forum Contributor IonutC's Avatar
    Join Date
    01-28-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    Office 2019
    Posts
    486

    Re: VB code to control Workbook2 form Workbook1

    Hi,

    Put your excel file so we can help. What do you want to do, after that sheet is activated?
    Please consider:
    Be polite. Thank those who have helped you.
    Click the star icon in the lower left part of the contributor's post and add Reputation. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .
    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Posting code between tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

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

    Re: VB code to control Workbook2 form Workbook1

    John

    If Sheet11 is the codename for the 'Transactions' tab you can't use it like this to refer to the worksheet.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    09-20-2008
    Location
    France
    Posts
    9

    Re: VB code to control Workbook2 form Workbook1

    Quote Originally Posted by Norie View Post
    John

    If Sheet11 is the codename for the 'Transactions' tab you can't use it like this to refer to the worksheet.
    Yes ............sheet11 is the (Name) in the properties ............and Transactions is the Name in the properties.

    I cannot post a jpeg image..............but I am sure you understand what I mean.

    How can I use it please ...........using the sheet11 reference ?

    Thank you for your help.

  5. #5
    Registered User
    Join Date
    09-20-2008
    Location
    France
    Posts
    9

    Re: VB code to control Workbook2 form Workbook1

    Quote Originally Posted by Norie View Post
    John

    If Sheet11 is the codename for the 'Transactions' tab you can't use it like this to refer to the worksheet.
    Yes ............sheet11 is the (Name) in the properties ............and Transactions is the Name in the properties.

    I cannot post a jpeg image..............but I am sure you understand what I mean.

    How can I use it please ...........using the sheet11 reference ?

    Thank you for your help.

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

    Re: VB code to control Workbook2 form Workbook1

    John

    Is either workbook the workbook the code is in?

    Why do you want to use the codename instead of the tab name?

  7. #7
    Registered User
    Join Date
    09-20-2008
    Location
    France
    Posts
    9

    Re: VB code to control Workbook2 form Workbook1

    Hi,

    The code is in Workbook1 and it controls Workbook2.

    Tab names can be changed very easily................The codename, or what I call the sheet name (sheet11) can be changed but people are less likely to change it.

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

    Re: VB code to control Workbook2 form Workbook1

    John

    You can't refer directly to a worksheet using its codename unless you programatically access the VBE and even then things are a bit 'indirect'

    To do that it would look something like this.
    Please Login or Register  to view this content.
    An alternative would be something like this.
    Please Login or Register  to view this content.
    That code is a bit simpler but if you had a lot of worksheets looping might slow things down a bit.

  9. #9
    Registered User
    Join Date
    09-20-2008
    Location
    France
    Posts
    9

    Re: VB code to control Workbook2 form Workbook1

    That is very kind of you Norie, thank you

    John

+ 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. VBA code to make of copy of workbook2 and then copy data in that from Workbook1
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-05-2015, 06:34 AM
  2. [SOLVED] open user Form in workbook1 from workbook2
    By Dariusd7 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 02-07-2014, 02:25 PM
  3. How to bring data from workbook1 to workbook2 by comparing values of workbook2
    By amethystfeb in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-04-2013, 09:38 AM
  4. Workbook1 should start Workbook2
    By KausBorealis in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-03-2012, 10:52 PM
  5. Move tab from Workbook1 to Workbook2 using Macro VBA
    By nachousa in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-08-2010, 11:58 AM
  6. Data from workbook1 to workbook2 every week but in different place in workbook2
    By cheelie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-29-2007, 06:26 PM
  7. Replies: 1
    Last Post: 05-18-2005, 09:06 AM

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