largeselection
Active Member
- Joined
- Aug 4, 2008
- Messages
- 358
Quick question, I want to reference a workbook that i mentioned quite a bit in my macro code. However, I want to be able to change this workbook by just changing one line of code rather than having to go into my rather long code to change it every time.
Here's what I have so far:
Dim MyFile As Workbook
Set MyFile = ActiveWorkbook
Dim MyTarget As Workbook
Set MyTarget = windows("week 28 O.xls")
Then later in the code I have it reference MyTarget and MyFile.
MyFile opens the current workbook that I am creating and I was hoping that I could put MyTarget.Activate into every instance where it occurs and it would reference week 28 o.xls. (originally when I recorded this it had "week 28 O.xls".activate) So what I figured is that rather than having to go in and change the 28 to a 29 in every instance in the code (about 25 of them) I would just set MyTarget = ___ that way if I want to change to week 29 in all those instances I just have to change the 28 to a 29 in the set MyTarget line and then all the references to my target would apply to the new week 29.
However I'm getting an error at the Set MyTarget = windows("week 28 O.xls") line.
I feel like this is probably an easy fix. Please ask any and all questions so I can help clarify.
Here's what I have so far:
Dim MyFile As Workbook
Set MyFile = ActiveWorkbook
Dim MyTarget As Workbook
Set MyTarget = windows("week 28 O.xls")
Then later in the code I have it reference MyTarget and MyFile.
MyFile opens the current workbook that I am creating and I was hoping that I could put MyTarget.Activate into every instance where it occurs and it would reference week 28 o.xls. (originally when I recorded this it had "week 28 O.xls".activate) So what I figured is that rather than having to go in and change the 28 to a 29 in every instance in the code (about 25 of them) I would just set MyTarget = ___ that way if I want to change to week 29 in all those instances I just have to change the 28 to a 29 in the set MyTarget line and then all the references to my target would apply to the new week 29.
However I'm getting an error at the Set MyTarget = windows("week 28 O.xls") line.
I feel like this is probably an easy fix. Please ask any and all questions so I can help clarify.