+ Reply to Thread
Results 1 to 10 of 10

assign variable name to the workbook

  1. #1
    Registered User
    Join Date
    04-12-2010
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    96

    Unhappy assign variable name to the workbook

    Hi, all. please help woth this problem.
    I want to open two file at the beginning of the code, like below, and after the two files are opened, i want to activate one of the file first, and i must write the exactly same name as the workbook name, then i can activate the window. Is there any way so that assign a variable to the workbook name, and any time, i call the variable, it will know which window should be activated.
    Please Login or Register  to view this content.
    in this example, the two file name are "PriceList" and "CombinedPriceList". If i change the file name to "PriceList01" and "CombinedPriceList01", then the macro will get error. so i want to overcome this problem.
    Any help will be appreciated!
    Last edited by yjmmay34; 08-17-2010 at 01:46 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: assign variable name to the workbook

    Like so:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: assign variable name to the workbook

    Hello,

    I'd tackle it this way:

    - count how many workbooks are currently open
    - open the first workbook with the macro
    - get the name of that workbook with the workbooks index into a string variable
    - open the second workbook with the macro
    - get the name of that workbook with the workbooks index into a string variable
    - open each workbook by its string variable

    something like

    Please Login or Register  to view this content.

  4. #4
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: assign variable name to the workbook

    JB, of course! Experience shows!

  5. #5
    Registered User
    Join Date
    04-12-2010
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    96

    Re: assign variable name to the workbook

    hello,Jbeaucaire. thank you for your help. please do me one more favour, i got another problem in this link.
    http://www.excelforum.com/excel-prog...-criteria.html
    Appreciated your help!!!

  6. #6
    Registered User
    Join Date
    04-12-2010
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    96

    Re: assign variable name to the workbook

    Thank you so much, teylyn. could you please check this link and help me with the problem? Thank you!
    http://www.excelforum.com/excel-prog...-criteria.html

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: assign variable name to the workbook

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  8. #8
    Registered User
    Join Date
    04-12-2010
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    96

    Re: assign variable name to the workbook

    Yes, Beaucaire. it really helps me a lot. And i have marked the post as solved. Could you please check the link above when you have time? Thank you so much!

  9. #9
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: assign variable name to the workbook

    yjmmay, people will get to your post in their own time. They will decide if they want to answer. You can't make them. Please don't push. We're all volunteers here, investing our own free time.

  10. #10
    Registered User
    Join Date
    04-12-2010
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    96

    Re: assign variable name to the workbook

    Yeah, i understand, just because i need this macro urgently, so maybe my words sounds unconfortable. Apologize for any thing wrong. Thank you for the advise!

+ 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