PhilippeMortreux
New Member
- Joined
- Jan 24, 2013
- Messages
- 3
hello,
In an addin, I need to handle 2 workbooks, unfortunately their names vary, so I don't know how to refer to them so that it would work.
1) I open the first workbook and save it under the variable WB1 (workbook1)
2) then I open the second workbook using the code and save it under another variable WB2 (workbook2)
I need to navigate from the one to the other in the code but It does not work if I refer to them using WB1 and WB2
If you have any suggestions it would be really helpful.
here is a simplified version of what I am trying to do:
PS: I understand that I cannot use "thisworkbook" as it is a Addin and there is no workbooks visible.
In an addin, I need to handle 2 workbooks, unfortunately their names vary, so I don't know how to refer to them so that it would work.
1) I open the first workbook and save it under the variable WB1 (workbook1)
2) then I open the second workbook using the code and save it under another variable WB2 (workbook2)
I need to navigate from the one to the other in the code but It does not work if I refer to them using WB1 and WB2
If you have any suggestions it would be really helpful.
here is a simplified version of what I am trying to do:
Code:
Sub NavigateBtweenWBks()
Dim WB1 as workbook
Dim WB2 as workbook
' Open the first workbook
Workbooks.Open Filename:="G:\path\Workbook1.xlsx"
set WB1 = activeworkbook
' Open the second workbook
Workbooks.Open Filename:="G:\path\Workbook2.xlsx"
set WB2 = activeworkbook
WB1.activate
' copy range("A1") from WB1 to WB2
WB1.sheets(1).range("A1").copy destination:=WB2.sheets(1).range("A1)
WB2.activate
WB1.close
end sub
PS: I understand that I cannot use "thisworkbook" as it is a Addin and there is no workbooks visible.