Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Does a worksheet exist

When a worksheet is named and copied from one workbook to another workbook
via a macro, is it possible to check whether that worksheet name already
exists and if so to paste over it and not make a new sheet, as in Worksheet
Name (1)?
--
n00b lookn for a handout
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Does a worksheet exist

You could...

But if you really want the new sheet in that other workbook, how about just
deleting it first?

Dim wksName as string
dim testwks as worksheet
wksname = activesheet.name

application.displayalerts = false 'not "are you sure prompt"
on error resume next 'in case it isn't there
otherworkbook.worksheets(wksname).delete
on error goto 0
application.displayalerts = true

Then do the copy.



Arnie wrote:

When a worksheet is named and copied from one workbook to another workbook
via a macro, is it possible to check whether that worksheet name already
exists and if so to paste over it and not make a new sheet, as in Worksheet
Name (1)?
--
n00b lookn for a handout


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Does a worksheet exist

This does seem to be a much simpler solution! To clarify tho, did you intend
for this code to go into the workbook that the sheet is being copied FROM or
TO? Since you're using ActiveSheet I'm guess it should go in the FROM
workbook, which means I would need to move my macro with the OnTime function
there as well?
--
n00b lookn for a handout


"Dave Peterson" wrote:

You could...

But if you really want the new sheet in that other workbook, how about just
deleting it first?

Dim wksName as string
dim testwks as worksheet
wksname = activesheet.name

application.displayalerts = false 'not "are you sure prompt"
on error resume next 'in case it isn't there
otherworkbook.worksheets(wksname).delete
on error goto 0
application.displayalerts = true

Then do the copy.



Arnie wrote:

When a worksheet is named and copied from one workbook to another workbook
via a macro, is it possible to check whether that worksheet name already
exists and if so to paste over it and not make a new sheet, as in Worksheet
Name (1)?
--
n00b lookn for a handout


--

Dave Peterson

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
Copy Worksheet to a new Workbook creating if it doesn't exist and add more Worksheets if it does exist [email protected] Excel Programming 4 June 18th 06 06:08 PM
File opens as worksheet.xls:1 and worksheet.xls:2. Only one exist Dave the wave[_2_] Excel Programming 5 January 30th 06 11:28 PM
Does a worksheet exist? papa jonah Excel Programming 2 January 5th 06 06:20 PM
Does a worksheet exist Kaval[_2_] Excel Programming 3 May 31st 04 07:21 AM
Does worksheet exist Robert S Excel Programming 3 May 18th 04 07:59 PM


All times are GMT +1. The time now is 07:11 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"