Hi,
I have two workbooks in the same folder. I want to have one workbook that will be manually opened by users, but that contains a macro within the workbook_open, that will open another workbook to pull data from. I wrote the code but its not working, I get an error asking me to debug and when I debug it points to this line ('Workbooks("Barcelona-metrics-new.xls").Sheets("WeeklyData").Select').
Just to explain a little, I included this line of code because it appeared excel was getting confused as to which workbook to add my Unique formulas code to. I thought I have to tell excel to open BarcelonaInternalActions.xls (which contains the main data), then tell it to switch to Barcelona-metrics-new.xls, which is where I want to copy formulas and pull data from the first workbook:
---------------------------------------------------------------
Private Sub Workbook_Open()
Workbooks.Open FileName:= _
"http://MyServer/sites/wtbu/umts/barcelona/Action Items/metrics/BarcelonaInternalActions.xls"
Workbooks("Barcelona-metrics-new.xls").Sheets("WeeklyData").Select
'Copy Unique Weeks formula
Range("Q1") = "UniqueWeeks"
Range("Q2") = "=IF(ROW()-ROW($Q$2)+1<=$P$2,INDEX(UNIQUEVALUES([BarcelonaInternalActions.xls]Metrics!$AB$2:$AB$5305,1),ROW()-ROW($Q$2)+1),"""")"
Range("Q2").Select
Selection.Copy
I have two workbooks in the same folder. I want to have one workbook that will be manually opened by users, but that contains a macro within the workbook_open, that will open another workbook to pull data from. I wrote the code but its not working, I get an error asking me to debug and when I debug it points to this line ('Workbooks("Barcelona-metrics-new.xls").Sheets("WeeklyData").Select').
Just to explain a little, I included this line of code because it appeared excel was getting confused as to which workbook to add my Unique formulas code to. I thought I have to tell excel to open BarcelonaInternalActions.xls (which contains the main data), then tell it to switch to Barcelona-metrics-new.xls, which is where I want to copy formulas and pull data from the first workbook:
---------------------------------------------------------------
Private Sub Workbook_Open()
Workbooks.Open FileName:= _
"http://MyServer/sites/wtbu/umts/barcelona/Action Items/metrics/BarcelonaInternalActions.xls"
Workbooks("Barcelona-metrics-new.xls").Sheets("WeeklyData").Select
'Copy Unique Weeks formula
Range("Q1") = "UniqueWeeks"
Range("Q2") = "=IF(ROW()-ROW($Q$2)+1<=$P$2,INDEX(UNIQUEVALUES([BarcelonaInternalActions.xls]Metrics!$AB$2:$AB$5305,1),ROW()-ROW($Q$2)+1),"""")"
Range("Q2").Select
Selection.Copy