Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Check if Userform exsists before deleting via VB

I have a block of code that deletes a form after I close it

ThisWorkbook.VBProject.VBComponents.Remove _
ThisWorkbook.VBProject.VBComponents("FormNameHere" )

I run this code before some code that rebuilds the form with new data.
The problem happens when the user aborts the macro in between the
form being delted and being recreated. If that happens the next time
I run the macro there is no form to delete and it fails.

How can I wrap this code so that it checks to see if this form exsists
first?
Rich
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Check if Userform exsists before deleting via VB

Rich,

I wasn't familiar with the syntax below before reading your message but this
seems to work. If it doesn't exist it doesn't cause an error:

On Error Resume Next
ThisWorkbook.VBProject.VBComponents.Remove _
ThisWorkbook.VBProject.VBComponents("UserForm1")
On Error GoTo 0

Alternately, the following tests for the existence of the form:

Sub test()

Dim uform As Object

On Error Resume Next
Set uform = ThisWorkbook.VBProject.VBComponents("UserForm1")
If Error < "" Then
MsgBox "no such form"
Else
MsgBox "form exists"
End If
On Error GoTo 0

End Sub

Tested in XP XL2000

hth,

Doug

"Rich" wrote in message
om...
I have a block of code that deletes a form after I close it

ThisWorkbook.VBProject.VBComponents.Remove _
ThisWorkbook.VBProject.VBComponents("FormNameHere" )

I run this code before some code that rebuilds the form with new data.
The problem happens when the user aborts the macro in between the
form being delted and being recreated. If that happens the next time
I run the macro there is no form to delete and it fails.

How can I wrap this code so that it checks to see if this form exsists
first?
Rich



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
Deleting cell data without deleting formula Tom Hall Excel Discussion (Misc queries) 4 October 29th 06 04:07 PM
"the file already exsists in this location do you want to replace. jenn Excel Discussion (Misc queries) 7 October 9th 06 07:19 PM
deleting values in a worksheet without deleting the formulas patti Excel Worksheet Functions 1 October 28th 05 09:49 PM
deleting check control box Brad Excel Discussion (Misc queries) 1 September 29th 05 08:21 PM
Problem Deleting Check Boxes created from Forms Toolbar Suzan Excel Discussion (Misc queries) 4 September 15th 05 06:30 PM


All times are GMT +1. The time now is 09:40 AM.

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"