Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default comman button macro can't open worksheet

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

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default comman button macro can't open worksheet


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


-----Original Message-----
I recorded a macro where i select a range for copy then

open a spcific
file go to sheet2 and paste.

i copy this code to a button macro, but when i tried to

run and click
the button it a run-time error 1004: "Method openof

object Workbooks
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 Sub


---
Message posted from http://www.ExcelForum.com/

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comman Button Brenda New Users to Excel 6 October 14th 08 05:33 AM
Comman Button to Save Worksheet as Workbook tmstreet Excel Discussion (Misc queries) 2 July 17th 06 05:44 PM
Auto filter through the Comman Button irsath Excel Worksheet Functions 2 July 3rd 06 01:04 PM
Easy one- Comman button close David Excel Programming 3 June 3rd 04 07:14 PM
Comman Button to open another application hutchuser007 Excel Programming 2 May 11th 04 12:56 PM


All times are GMT +1. The time now is 01:46 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"