Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Activate Workbook by Variable Name????

Status
Not open for further replies.

jennuhw

MIS
Apr 18, 2001
426
US
I have a script that saves a workbook to a certain filename (based on cell values.) I need to reopen the workbook (with the new file name) and refer to itself while running a macro. This is what I currently have and has failed:

Qty1 = Range("F6").FormulaR1C1
P1 = Range("D6").FormulaR1C1
customer_code = Range("C6")
fname = customer_code + " " + P1 + " " + Qty1
Workbooks(fname).Activate

It is giving me an error. Any ideas?
 
I have figured it out!! I had to add + ".xls" at the end of the line that generates the file name. So it looks like this:
fname = customer_code + " " + P1 + " " + Qty1 + ".xls"

:)I
 
Hi,
You can also do something like this...
Code:
Dim wbkNewName as Workbook, wbkThis as Workbook

Set wbkThis = ActiveWorkbook
...
' open the workbook
Open...
Set wbkNewName = ActiveWorkbook
...
wbkNewName.Activate
'do stuff in NewName workbook
...
wbkTHis.Activate
'do stuff in This workbook
Lots of ways to skin a cat :)
Skip,
metzgsk@voughtaircraft.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top