+ Reply to Thread
Results 1 to 8 of 8

Active workbook selection

  1. #1
    Registered User
    Join Date
    09-22-2012
    Location
    colombo,srilanka
    MS-Off Ver
    Excel 2007
    Posts
    11

    Active workbook selection

    I have written a following code in a macro for a active excel sheet
    Please Login or Register  to view this content.
    but this file name abc2 changes time to time, therefore i want to type the new file name in a excel cell and that new file name need to be be updated in the macro above or i want a macro that name of the work book that need to be active given in excel cell.

    Regards,
    Althaf

  2. #2
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Active workbook selection

    Hi Althaf,

    I guess, anyhow you need to type the name of the workbook or get it stored in a variable as the name will keep on changing.

    To type the name of the workbook, you can use a input box as i = inputbox("workbook name") and then you can use that further in the code as windows(i).activate. You can also type the workbook name in a cell and get that value stored in i.

    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), dilipandey@gmail.com

  3. #3
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Active workbook selection

    Instead of using the Sheet Name, just use the Sheet# i.e.:

    If it is Sheet 2 that is named "abc2.xlsx", then use only the Sheet #

    Please Login or Register  to view this content.
    Now you may change the name of Sheet2 as many times you like, the Code will allways take you to Sheet2.

    If you want to keep track of a WorkBook of which the Name changes often, then in that same WorkBook, go to the WorkBook Before Close Event and in there you enter Code to update say Cell C10 of the other open WorkBook, which in turn you could use to find the new name.


    Hope that helps.
    Last edited by Winon; 09-23-2012 at 01:56 AM. Reason: Unsure about actual requirement
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Active workbook selection

    Hi, Althaf,

    it would be best to avoid jumping in between windows or workbooks by opening the workbook and setting an object on that:

    Please Login or Register  to view this content.
    Later on you can fulfill any action by using wbToOpen for the new workbook and ThisWorkbook for the workbook with the code.

    Please Login or Register  to view this content.
    assuming in cell A1 is drive, folder and name of workbook like C:\Temp\NewBook120923.xlsx.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  5. #5
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Active workbook selection

    @ HaHoBe,

    Hello Holger,

    Nice! I could not do it better since I was uncertain as to what exactly was required.

  6. #6
    Registered User
    Join Date
    09-22-2012
    Location
    colombo,srilanka
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Active workbook selection

    Dear Ciao and Winon,

    i cant go with sheet names coz i will have to open about 6 excel files (sheet 1 will be common for all opened excel files) and same macro will be run on each excel file. so i want a way to activate those excel files by giving their names in a excel files or some other way to run the macro...

  7. #7
    Registered User
    Join Date
    09-22-2012
    Location
    colombo,srilanka
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Active workbook selection

    Dear Dilipandey,

    Im not a expert in macro...so can you please give me an example ( simple one) for typing the work bookname in a cell and getting that value in to i

    thanks,
    Althaf

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Active workbook selection

    Hi, Althaf,

    in your very first thread in this Forum I pointed out to use Application.GetOpenFilename - and I repeat this again. The value retained from there can be used to set an object - if you really need 6 open workbooks to switch around any collection could handle the name of these instead of questioning these via (according to my opinion) the weakest possibility of all InputBox (open to typos like I´m master on ).

    Please Login or Register  to view this content.
    HTH
    Holger <-- that´s my name

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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