comman button macro can't open worksheet

  • Thread starter Thread starter b_yousif
  • Start date Start date
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top