ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Test for text boxes (https://www.excelbanter.com/excel-programming/435231-test-text-boxes.html)

Jim G

Test for text boxes
 
I want to test for a text box ("text box 2"). If it exists delete it if not
do nothing.

I can delete the text box with 'Worksheets("Expense").TextBoxes("textbox
2").Delete' before I print the sheet. However, if the worksheet is reprinted
it comes up with an error because it can't find the text box.

Any suggestions appreciated.
--
Jim

Per Jessen

Test for text boxes
 
Hi Jim

You can use the error handler:

On Error Resume Next
Worksheets("Sheet3").TextBoxes("Expense").Delete
On Error GoTo 0

Regards,
Per

"Jim G" skrev i meddelelsen
...
I want to test for a text box ("text box 2"). If it exists delete it if
not
do nothing.

I can delete the text box with 'Worksheets("Expense").TextBoxes("textbox
2").Delete' before I print the sheet. However, if the worksheet is
reprinted
it comes up with an error because it can't find the text box.

Any suggestions appreciated.
--
Jim



joel[_48_]

Test for text boxes
 

Found = False
For Each bx In ActiveSheet.TextBoxes
If bx.Name = "textbox2" Then
Found = True
Exit For
End If
Next bx


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=146348


GerryGerry

Test for text boxes
 
If you know the number of textboxes on the sheet you could alway use
("Expense").TextBoxes.count to see first if it exists.

You could (not advisable) preface the delelete statement with 'on error
resume next'

or you could use :
if isobject(("Expense").TextBoxes("textbox 2")) then
Worksheets("Expense").TextBoxes("textbox 2").Delete
end if


"Jim G" wrote in message
...
I want to test for a text box ("text box 2"). If it exists delete it if
not
do nothing.

I can delete the text box with 'Worksheets("Expense").TextBoxes("textbox
2").Delete' before I print the sheet. However, if the worksheet is
reprinted
it comes up with an error because it can't find the text box.

Any suggestions appreciated.
--
Jim




Sam Wilson

Test for text boxes
 
Use:

On Error Resume Next
Worksheets("Expense").TextBoxes("textbox2").Delete

This will skip over the error caused by trying to delete something that
doesn't exist.

Sam


"Jim G" wrote:

I want to test for a text box ("text box 2"). If it exists delete it if not
do nothing.

I can delete the text box with 'Worksheets("Expense").TextBoxes("textbox
2").Delete' before I print the sheet. However, if the worksheet is reprinted
it comes up with an error because it can't find the text box.

Any suggestions appreciated.
--
Jim


Jim G

Test for text boxes
 
This worked;
If Worksheets("Expense").TextBoxes.Count 0 Then
Worksheets("Expense").TextBoxes("textbox 2").Delete
Else: Exit Sub

I'd tried it before but didn't realise it needed 'Worksheets("Expense").'

'if isobject(("Expense").TextBoxes("textbox 2")) then' didn't work. The
line stayed red no what I did.

Thanks for the help
--
Jim


"GerryGerry" wrote:

If you know the number of textboxes on the sheet you could alway use
("Expense").TextBoxes.count to see first if it exists.

You could (not advisable) preface the delelete statement with 'on error
resume next'

or you could use :
if isobject(("Expense").TextBoxes("textbox 2")) then
Worksheets("Expense").TextBoxes("textbox 2").Delete
end if


"Jim G" wrote in message
...
I want to test for a text box ("text box 2"). If it exists delete it if
not
do nothing.

I can delete the text box with 'Worksheets("Expense").TextBoxes("textbox
2").Delete' before I print the sheet. However, if the worksheet is
reprinted
it comes up with an error because it can't find the text box.

Any suggestions appreciated.
--
Jim



.


Jim G

Test for text boxes
 
I tried this to no avail:
Found = False
For Each bx In ActiveSheet.TextBoxes
If bx.Name = "textbox 2" Then '<<<added the space
Worksheets("Expense").TextBoxes("textbox 2").Delete
Found = True
Exit For
End If
Next bx

What would I be missing?
--
Jim


"joel" wrote:


Found = False
For Each bx In ActiveSheet.TextBoxes
If bx.Name = "textbox2" Then
Found = True
Exit For
End If
Next bx


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=146348

.


Per Jessen

Test for text boxes
 
Hi

Try this, and please note, that excel does not accept spaces in textbox
names.

Dim found As Boolean
found = False
For Each bx In Worksheets("Expense").Shapes
If bx.Name = "TextBox2" Then
Worksheets("Expense").Shapes("TextBox2").Delete
found = True
Exit For
End If
Next bx

Regards,
Per

"Jim G" skrev i meddelelsen
...
I tried this to no avail:
Found = False
For Each bx In ActiveSheet.TextBoxes
If bx.Name = "textbox 2" Then '<<<added the space
Worksheets("Expense").TextBoxes("textbox 2").Delete
Found = True
Exit For
End If
Next bx

What would I be missing?
--
Jim


"joel" wrote:


Found = False
For Each bx In ActiveSheet.TextBoxes
If bx.Name = "textbox2" Then
Found = True
Exit For
End If
Next bx


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread:
http://www.thecodecage.com/forumz/sh...d.php?t=146348

.




All times are GMT +1. The time now is 10:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com