excel - Run-time error '9' when copying worksheet to another workbook -


i've been trying write macro copy "sheet1" 1 workbook another, keep getting run-time error '9': subscript out of range.

sub copysheettootherwbk()  dim copyfrombook workbook dim copytowbk workbook dim shtocopy worksheet  set copyfrombook = workbooks("allbugs.xlsx") set shtocopy = copyfrombook.worksheets("sheet1") set copytowbk = workbooks("yourfriendlyneighborhoodtemplateworksheet.xlsx")  shtocopy.copy after:=copytowbk.sheets(copytowbk.sheets.count)  end sub 

the highlighted line "set copyfrombook = workbooks("allbugs.xlsx")". not sure i'm doing wrong here. relatively new vba. appreciated.

the workbooks collection refers open workbooks. if workbook isn't open need first.

set copyfrombook = workbooks.open("c:\some location\allbugs.xlsx") 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -