Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If you have only WB1 and one other (visible) workbook open, you can use code
like Dim WB1 As Workbook Dim WB As Workbook For Each WB In Workbooks If WB.Windows(1).Visible = True Then If WB.Name < ThisWorkbook.Name Then Set WB1 = WB Exit For End If End If Next WB Debug.Print WB.Name -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com (email address is on the web site) "Jason" wrote in message ... I am trying to use some code to copy and paste a variety of cells from a master workbook ("WB1", which contains the code) to a second WB ("WB2"). The name of WB1 is fixed and will not change. However, WB2 will not always have the same filename. I would generally only be doing this one workbook at a time, i.e. I will have WB1 open along with WB2, and then run the code. Is there a way using code to reference/activate WB2 while I am in WB1 without having to use the filename of WB2 (it will not always be the same)? Thanks. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Chip, I am not sure I follow. I've pasted my code to give a better
understanding of what I want to do. How would I integrate your suggestion to make it work? Workbooks("WB1").Activate Sheets("Sheet1").Activate Range("K20").Copy Workbooks("Unknown Name").Activate ' This is where I am getting hung up. Given that I don't know what the name of the workbook will be (it is always changing), I don't know how to activate it so that I can toggle between the two workbooks Sheets("Sheets1").Activate Range("K20").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Workbooks("WB1").Activate Sheets("Sheet1").Activate Range("A13").Copy This process will continue on as I copy and paste a number of cells from one workbook to another. "Chip Pearson" wrote: If you have only WB1 and one other (visible) workbook open, you can use code like Dim WB1 As Workbook Dim WB As Workbook For Each WB In Workbooks If WB.Windows(1).Visible = True Then If WB.Name < ThisWorkbook.Name Then Set WB1 = WB Exit For End If End If Next WB Debug.Print WB.Name -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com (email address is on the web site) "Jason" wrote in message ... I am trying to use some code to copy and paste a variety of cells from a master workbook ("WB1", which contains the code) to a second WB ("WB2"). The name of WB1 is fixed and will not change. However, WB2 will not always have the same filename. I would generally only be doing this one workbook at a time, i.e. I will have WB1 open along with WB2, and then run the code. Is there a way using code to reference/activate WB2 while I am in WB1 without having to use the filename of WB2 (it will not always be the same)? Thanks. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Jason,
Using the code I posted, you don't access the other, unknown workbook with Workbooks("Unknown Name").Activate Instead, the code I posted has a variable of type Workbook named WB1 that will refer to the unknown workbook. Therefore, instead of Workbooks("Unknown Name").Activate you'd use WB1.Activate Or, if you prefer, Workbooks(WB1.Name).Activate -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com (email address is on the web site) "Jason" wrote in message ... Chip, I am not sure I follow. I've pasted my code to give a better understanding of what I want to do. How would I integrate your suggestion to make it work? Workbooks("WB1").Activate Sheets("Sheet1").Activate Range("K20").Copy Workbooks("Unknown Name").Activate ' This is where I am getting hung up. Given that I don't know what the name of the workbook will be (it is always changing), I don't know how to activate it so that I can toggle between the two workbooks Sheets("Sheets1").Activate Range("K20").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Workbooks("WB1").Activate Sheets("Sheet1").Activate Range("A13").Copy This process will continue on as I copy and paste a number of cells from one workbook to another. "Chip Pearson" wrote: If you have only WB1 and one other (visible) workbook open, you can use code like Dim WB1 As Workbook Dim WB As Workbook For Each WB In Workbooks If WB.Windows(1).Visible = True Then If WB.Name < ThisWorkbook.Name Then Set WB1 = WB Exit For End If End If Next WB Debug.Print WB.Name -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com (email address is on the web site) "Jason" wrote in message ... I am trying to use some code to copy and paste a variety of cells from a master workbook ("WB1", which contains the code) to a second WB ("WB2"). The name of WB1 is fixed and will not change. However, WB2 will not always have the same filename. I would generally only be doing this one workbook at a time, i.e. I will have WB1 open along with WB2, and then run the code. Is there a way using code to reference/activate WB2 while I am in WB1 without having to use the filename of WB2 (it will not always be the same)? Thanks. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
That worked perfectly. Thanks to all for your responses.
Jason "Chip Pearson" wrote: Jason, Using the code I posted, you don't access the other, unknown workbook with Workbooks("Unknown Name").Activate Instead, the code I posted has a variable of type Workbook named WB1 that will refer to the unknown workbook. Therefore, instead of Workbooks("Unknown Name").Activate you'd use WB1.Activate Or, if you prefer, Workbooks(WB1.Name).Activate -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com (email address is on the web site) "Jason" wrote in message ... Chip, I am not sure I follow. I've pasted my code to give a better understanding of what I want to do. How would I integrate your suggestion to make it work? Workbooks("WB1").Activate Sheets("Sheet1").Activate Range("K20").Copy Workbooks("Unknown Name").Activate ' This is where I am getting hung up. Given that I don't know what the name of the workbook will be (it is always changing), I don't know how to activate it so that I can toggle between the two workbooks Sheets("Sheets1").Activate Range("K20").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Workbooks("WB1").Activate Sheets("Sheet1").Activate Range("A13").Copy This process will continue on as I copy and paste a number of cells from one workbook to another. "Chip Pearson" wrote: If you have only WB1 and one other (visible) workbook open, you can use code like Dim WB1 As Workbook Dim WB As Workbook For Each WB In Workbooks If WB.Windows(1).Visible = True Then If WB.Name < ThisWorkbook.Name Then Set WB1 = WB Exit For End If End If Next WB Debug.Print WB.Name -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com (email address is on the web site) "Jason" wrote in message ... I am trying to use some code to copy and paste a variety of cells from a master workbook ("WB1", which contains the code) to a second WB ("WB2"). The name of WB1 is fixed and will not change. However, WB2 will not always have the same filename. I would generally only be doing this one workbook at a time, i.e. I will have WB1 open along with WB2, and then run the code. Is there a way using code to reference/activate WB2 while I am in WB1 without having to use the filename of WB2 (it will not always be the same)? Thanks. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Activating a workbook | Excel Programming | |||
Activating previously used workbook | Excel Programming | |||
activating a workbook | Excel Programming | |||
Activating workbook with variable Name | Excel Programming | |||
Activating a workbook help | Excel Programming |