Command button code

G

Guest

I have a macro that I created and I have copied the code from it to the code
area for a command button and when I execute the command button it does not
work but if I execute the macro it does. see the code for both below, I
receive the error Selected method of range class failed

Macro:

Private Sub CommandButton2_Click()
Range("A1:E1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ChDir "\\nysyrfsv04\shared\UGTREAS\P & C"
Workbooks.Open Filename:= _
"\\nysyrfsv04\shared\UGTREAS\P & C\Current Third Party.xls"
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWorkbook.Save
ActiveWorkbook.Close
Range("A2:E2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Range("A2").Select
End Sub

Command:
Private Sub CommandButton3_Click()
Range("A2").Select
Workbooks.Open Filename:= _
"\\nysyrfsv04\shared\UGTREAS\P & C\Current Third Party.xls"
Range("A2:E2").Select ******Error here *******
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ActiveWindow.Close
ActiveSheet.Paste
Range("A2").Select
ActiveWorkbook.Save
End Sub
 
M

masterbigggy

the way im doing it when i use button

rigth click on the button and do assign macro !!
 
B

Bob Phillips

That code should probably be in the worksheet code module that the button is
on.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
G

Guest

I do not get the option to assign a macro. I am using excel 2003 and when I
right click on the button there is no option for assign a macro
 

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

Top