Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 26th, 2007, 07:10 PM
Authorized User
 
Join Date: Mar 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to jgrant
Default copy error

I have this excel file that I have created. I wanted to set it up to be multi-user friendly. So essentially what i have done was at startup, i ask for a user name and password. Then the code runs through a worksheet and checks for user name and password. If the password cannot be verified it copies a worksheet for the user to fill out. But for some reason I keep getting an error on the copy worksheet routine. Here is the code:

Private Sub CopySheets()
Dim wsh As Worksheet
ActiveWorkbook.Sheets("SRC").Copy _
After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets .Count)
Set wsh = ActiveSheet
wsh.Name = userName & " SRC"

The error im getting is a Run-time error '1004', Application-defined or object-defined error.

I have tried using the code several different ways but I have not been able to get it to work. Can anyone give me a reccomendation?



 
Old March 26th, 2007, 11:37 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

The error occurs because your are creating or renaming a sheet which already exist

wsh.Name = UserName & " SRC"

i.e,, you already have a sheet called SRC in the workbook. Try it with a different name. If you are creating sheets in the same workbook for all users, then you need to go for a prefix to each sheet name

Cheers
Shasur



http://www.vbadud.blogspot.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy visible cells in a macro?Runtime 438 error? nbaj2k Excel VBA 2 April 7th, 2010 11:13 AM
copy sheets jgrant Beginning VB 6 0 March 26th, 2007 01:42 PM
copy value in VB ct Excel VBA 1 August 23rd, 2005 02:38 AM
File copy routine error! Janet C++ Programming 3 March 13th, 2004 02:41 PM
Image copy amita VB Components 0 August 26th, 2003 10:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.