Thread: Form help
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Anders Silven Anders Silven is offline
external usenet poster
 
Posts: 25
Default Form help

Michael,

What is the code for CommandButton2?

The following works for me loading (and showing) UserForm2 after UserForm1 has
been unloaded,

In a Code Module:
'*****
Sub test764()
UserForm1.Show
Load UserForm2
UserForm2.Show
End Sub
'*****

In the code for UserForm1:
'*****
Private Sub CommandButton2_Click()
Unload UserForm1
End Sub
'*****

Regards
Anders Silven

"Michael Malinsky" skrev i meddelandet
...
I have the following code:

UserForm1.Show
Load UserForm2

UserForm1 has ListBox1 of open workbooks and RefEdit1 control as well as
CommandButton1 and CommandButton2. Clicking CommandButton1 runs code that
copies the range selected in RefEdit1 to a specified area - no problems
here. CommandButton2 is supposed to be a Cancel button and is where the
problem is. When the Cancel button on UserForm1 is clicked, I want to
unload UserForm1 and continue to the next line of code, which is to Load
UserForm2. At this point, I get the Application-defined or object-defined
error (runtime error 1004). If, on UserForm1, I select a range and click
the OK button, everything works fine, the code bombs out if I Cancel. Any
thoughts?

Also, I may change the code to completely dump out of the macro upon
clicking CommandButton2 on UserForm1. How would I do this?

TIA

--
Michael J. Malinsky
Pittsburgh, PA

"I am a bear of very little brain, and long
words bother me." -- AA Milne, Winnie the Pooh