AndresHernando
asked on
Activate Workbook and Worksheet with Wildcard
I need to activate a workbook and worksheet that will already be open. I have code that works for this for the specific name, but the date at the beginning will change every month, so I want code that will use a wildcard for the date and select the workbook and worksheet for activation just using the last part of the name.
Example:
This is what works now:
Workbooks("2011_09_Name_of _Workbook. xlsm").She ets("2011_ 09_Workshe et_Name"). Activate
This is the basic idea of what I would like to work:
Workbooks("*_Name_of_Workb ook.xlsm") .Sheets("* _Worksheet _Name").Ac tivate
Thank you
Example:
This is what works now:
Workbooks("2011_09_Name_of
This is the basic idea of what I would like to work:
Workbooks("*_Name_of_Workb
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
jpp,
Nevermind that last post. I forgot to change the "*_Name_of_Workbook.xlsm" back to the proper name. Once I changed it to the proper name, it loops through 3 times, and on the 3rd try it activates like it is supposed to. Not sure why it failed on me before? But it works now.
Thanks!
Nevermind that last post. I forgot to change the "*_Name_of_Workbook.xlsm" back to the proper name. Once I changed it to the proper name, it loops through 3 times, and on the 3rd try it activates like it is supposed to. Not sure why it failed on me before? But it works now.
Thanks!
ASKER
It worked
ASKER
Oh, I didn't notice until I tried to run it again that the code didn't call the spreadsheet within the workbook too. Do you know how I could call the spreadsheet within this workbook? To make matters more difficult, other open workbooks (with different names) will have a worksheet in them with the same name. That's why I need to make sure that it only calls the sheet within the active workbook.
ASKER
Nevermind that last one, I got it.
Thanks again.
Thanks again.
ASKER
I tried code like that before posting, but it didn't work. But I figured I'd give yours a try again anyhow. It still doesn't work. It seems to skip over the "wkb.activate" command when I step through it. It will loop a couple of times, and then just move on the the next portion of code. It doesn't crash or give an error msg, but it doesn't activate the workbook and worksheet that I want to be activated.
Thanks