#1   Report Post  
Posted to microsoft.public.excel.misc
CWillis
 
Posts: n/a
Default Check for existence

I am pasting a text box using a macro. I would like for the macro to make
sure that a text box doesn't already exist under the same name.
If it does, delete it and then paste the new one.
If it doesn't, paste the new one.
Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.misc
mrice
 
Posts: n/a
Default Check for existence


Try this...


Sub Macro1()
For Each Shape In ActiveSheet.Shapes
If Shape.Name = "MyTextBoxName" Then
Shape.delete
End If
Next Shape

Insert your PASTE code here


End Sub


--
mrice

Research Scientist with many years of spreadsheet development experience
------------------------------------------------------------------------
mrice's Profile: http://www.excelforum.com/member.php...o&userid=10931
View this thread: http://www.excelforum.com/showthread...hreadid=546853

  #3   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Check for existence

You could check first, but if you're going to delete it, why not just delete it?

'if the textbox is from the Drawing toolbar
On Error Resume Next
ActiveSheet.TextBoxes("text box 1").Delete
On Error GoTo 0

'if the textbox is from the control toolbox toolbar
On Error Resume Next
ActiveSheet.OLEObjects("textbox1").Delete
On Error GoTo 0

If the textbox isn't there to be deleted, the "on error resume next" line will
tell excel to ignore the error.

But you could just move/resize the existing one...



CWillis wrote:

I am pasting a text box using a macro. I would like for the macro to make
sure that a text box doesn't already exist under the same name.
If it does, delete it and then paste the new one.
If it doesn't, paste the new one.
Thanks in advance.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
CWillis
 
Posts: n/a
Default Check for existence

Thank you! Both will work. Plus some of that code will help with something
I have later. Thanks again.

"Dave Peterson" wrote:

You could check first, but if you're going to delete it, why not just delete it?

'if the textbox is from the Drawing toolbar
On Error Resume Next
ActiveSheet.TextBoxes("text box 1").Delete
On Error GoTo 0

'if the textbox is from the control toolbox toolbar
On Error Resume Next
ActiveSheet.OLEObjects("textbox1").Delete
On Error GoTo 0

If the textbox isn't there to be deleted, the "on error resume next" line will
tell excel to ignore the error.

But you could just move/resize the existing one...



CWillis wrote:

I am pasting a text box using a macro. I would like for the macro to make
sure that a text box doesn't already exist under the same name.
If it does, delete it and then paste the new one.
If it doesn't, paste the new one.
Thanks in advance.


--

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
... Can I set Spell Check to automatically check my spelling ... Dr. Darrell Setting up and Configuration of Excel 0 March 21st 06 08:26 PM
Entry into check box dependent on other check box. Stilla Excel Worksheet Functions 9 December 10th 05 03:44 PM
Can you sort with check boxes? Q Excel Discussion (Misc queries) 3 November 10th 05 08:11 PM
check boxes - copy MarkT Excel Discussion (Misc queries) 2 October 20th 05 04:33 PM
Creating a check box that does not require security clearance. Maverick2U Excel Worksheet Functions 6 December 14th 04 02:46 AM


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