Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / July 2004

Tip: Looking for answers? Try searching our database.

Run-time error 1004

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lee Jeffery - 06 Jul 2004 08:36 GMT
I am using Excel 97 on NT and have a command button on a sheet to whic
I attached a macro for copying the sheet to a new workbook, deletin
specific columns and other unnecessary info, and saving the new book t
a network drive under a name with today's date for emailing to anothe
area.

When I perform the function manually everything works beautifully bu
when I attempt to execute the macro I get the following error
"Run-time error '1004': Copy method of worksheet class failed". when
use the Debug button, VBA highlights Sheets("Daily").Copy as th
culprit. Macro follows:

Private Sub CommandButton2_Click()
Sheets("Daily").Select
Sheets("Daily").Copy
ActiveWorkbook.Activate
Columns("H:J").Select
Selection.Delete Shift:=xlToLeft
ActiveSheet.Shapes("CommandButton2").Select
Selection.Delete
ActiveSheet.Shapes("CommandButton1").Select
Selection.Delete
Range("B4").Select
ActiveWorkbook.SaveAs FileName:= _
"G:\ER\ECM-POL Commencements\POL Commencements_05-07-2004.xls"
FileFormat:= _
xlNormal, Password:="", WriteResPassword:=""
ReadOnlyRecommended:=True, _
CreateBackup:=True
ActiveWorkbook.Close
End Sub

The code is a little heavier than my original macro as I tried
different approach to get this going but have not succeeded.

I had this working fine on my home PC using Excel 97 on XP so I don'
understand why this has decided to spit the dummy now.

Can anyone help shed some light on this, please?:eek

--
Message posted from http://www.ExcelForum.com
Nick Hodge - 06 Jul 2004 20:55 GMT
Lee

Just a long shot by try going into the properties of your commandbutton and
setting the TakeFocusOnClick property to False

Signature

HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
nick_hodgeTAKETHISOUT@zen.co.uk.ANDTHIS

> I am using Excel 97 on NT and have a command button on a sheet to which
> I attached a macro for copying the sheet to a new workbook, deleting
[quoted text clipped - 38 lines]
> ---
> Message posted from http://www.ExcelForum.com/
Lee Jeffery - 07 Jul 2004 01:48 GMT
Thanks, Nick.

I did this and progressed past Sheets("Daily").Copy but now bomb out o
Columns("H:J").Select. I now get Run-time error "1004": Select metho
of Range class failed.

Any further thoughts, please? This is driving me to coffee!

Any suggestions would be very welcome

--
Message posted from http://www.ExcelForum.com
Nick Hodge - 07 Jul 2004 21:49 GMT
Lee

The recorded code is ugly with all the activations and selects which are not
necessary really, I've tidied it up a little, presuming the CommandButtons
are on the worksheet you are copying to another book and then deleting them.
Note: very little selecting, apart from where I thought it may be you
wanting to end with a certain cell selected.

Private Sub CommandButton2_Click()
Sheets("Daily").Copy
With ActiveSheet
   .Columns("H:J").Delete Shift:=xlToLeft
   .Shapes("CommandButton2").Delete
   .Shapes("CommandButton1").Delete
End With
ActiveSheet.Range("B4").Select
With ActiveWorkbook
   .SaveAs Filename:="G:\ER\ECM-POL Commencements\POL
Commencements_05-07-2004.xls"
   .Close
End With
End Sub

Signature

HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
nick_hodgeTAKETHISOUT@zen.co.uk.ANDTHIS

> Thanks, Nick.
>
[quoted text clipped - 8 lines]
> ---
> Message posted from http://www.ExcelForum.com/
Lee Jeffery - 08 Jul 2004 02:29 GMT
Nick,

You are a wonderful person! This works beautifully.  I'll be able t
get some sleep now I don't have to drink extra coffee!!

Your suggestion has just helped me finalise a huge productivit
improvement and I am very grateful for your assistance.

Thanks again.

P.S. I've enrolled in an Excel/VBA class so I can learn a lot mor
about the correct way to go about producing code for the fairly basi
things I need to do with Excel

--
Message posted from http://www.ExcelForum.com
Nick Hodge - 08 Jul 2004 07:14 GMT
Lee

Pleasure.

Stick around here too.  It's amazing what you pick up which spurs you on to
the next project

Signature

HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
nick_hodgeTAKETHISOUT@zen.co.uk.ANDTHIS

> Nick,
>
[quoted text clipped - 12 lines]
> ---
> Message posted from http://www.ExcelForum.com/
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.