comman button macro can't open worksheet

B

b_yousif

I recorded a macro where i select a range for copy then open a spcifi
file go to sheet2 and paste.

i copy this code to a button macro, but when i tried to run and clic
the button it a run-time error 1004: "Method openof object Workbook
failed "
the code is as follow under sheet1 (code):


Sub CommandButton1_Click()
Range("D2:H51").Select
Selection.copy
Workbooks.Open Filename:="Z:\My documents\myfile.xls"
Sheets("Sheet2").Select
Range("A10").Activate
ActiveSheet.Paste
End Su
 
H

Helen Trim

The problem here is where the macro is stored. It needs
to be in a module, not in the sheet's code. Open the
Visual Basic Editor and from the Insert menu, select
Module. Cut and paste the macro into the module. Assign
the macro to the button again.

HTH
Helen
 
Top