Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default UserForm_Initialize, how to exit sub based on condition?

IO hope I can explain this, I have a userform that will open on a button
click from a worksheet. First thing I am doing is testing the file name to
ensure the user won't overwrite the master file.
I can do that easily enough, the trouble I have is if the condition is true
(they are using the master file) I prompt with a msgbox and then wish to exit
the sub but the userform loads anyhow.
'=======
Private Sub UserForm_Initialize()
'other code removed
If Left(ActiveWorkbook.Name, 12) = "Template DIP" Then
MsgBox "Please do not edit This file! Use ""Save as"" prior to editing!"
End If
End Sub
'=======
No matter what I try I can not stop the userform from loading if the above
condition is true.

--
Regards

VBA.Noob.Confused
XP Pro
Office 2007

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default UserForm_Initialize, how to exit sub based on condition?

Private Sub UserForm_Initialize()
'other code removed
If Left(ActiveWorkbook.Name, 12) = "Template DIP" Then
MsgBox "Please do not edit This file! Use ""Save as"" prior to editing!"
Unload Me
End If
End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Rick S." wrote in message
...
IO hope I can explain this, I have a userform that will open on a button
click from a worksheet. First thing I am doing is testing the file name
to
ensure the user won't overwrite the master file.
I can do that easily enough, the trouble I have is if the condition is
true
(they are using the master file) I prompt with a msgbox and then wish to
exit
the sub but the userform loads anyhow.
'=======
Private Sub UserForm_Initialize()
'other code removed
If Left(ActiveWorkbook.Name, 12) = "Template DIP" Then
MsgBox "Please do not edit This file! Use ""Save as"" prior to editing!"
End If
End Sub
'=======
No matter what I try I can not stop the userform from loading if the above
condition is true.

--
Regards

VBA.Noob.Confused
XP Pro
Office 2007



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default UserForm_Initialize, how to exit sub based on condition?

Thanks Bob! I new I tried that, I get an error:
Runtime Error 91
Object variable or With block variable not set"

The error brings me back to this code.
'=======
Sub DipCreatorRun()
Dim i As Variant
Dim xDate As String

xDate = Range("I28").Value
Sheets("Sheet1").Select

Set WB = ActiveWorkbook
For i = 1 To Worksheets.Count
Sheets(i).Activate
Next
If Worksheets.Count <= 1 Then
DipCreatorForm.Show <<<<ERROR DEBUGS TO THIS LINE
Else
MsgBox "This workbook has been previously created on this date: " &
vbNewLine & xDate & vbNewLine & "You can not rerun ""DIP Creator"" on an
existing DIP!"""
End If
Sheets("Sheet1").Select
End Sub
'=======
The above Sub is what starts the entire process from a command button on a
worksheet.

--
Regards

VBA.Noob.Confused
XP Pro
Office 2007



"Bob Phillips" wrote:

Private Sub UserForm_Initialize()
'other code removed
If Left(ActiveWorkbook.Name, 12) = "Template DIP" Then
MsgBox "Please do not edit This file! Use ""Save as"" prior to editing!"
Unload Me
End If
End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Rick S." wrote in message
...
IO hope I can explain this, I have a userform that will open on a button
click from a worksheet. First thing I am doing is testing the file name
to
ensure the user won't overwrite the master file.
I can do that easily enough, the trouble I have is if the condition is
true
(they are using the master file) I prompt with a msgbox and then wish to
exit
the sub but the userform loads anyhow.
'=======
Private Sub UserForm_Initialize()
'other code removed
If Left(ActiveWorkbook.Name, 12) = "Template DIP" Then
MsgBox "Please do not edit This file! Use ""Save as"" prior to editing!"
End If
End Sub
'=======
No matter what I try I can not stop the userform from loading if the above
condition is true.

--
Regards

VBA.Noob.Confused
XP Pro
Office 2007




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default UserForm_Initialize, how to exit sub based on condition?

So it does, you can't unload it presumably because it isn't yet loaded.

Try this variation

Private fExit As Boolean

Private Sub UserForm_Activate()
If fExit Then Unload Me
End Sub

Private Sub UserForm_Initialize()
'other code removed
If Left(ActiveWorkbook.Name, 12) = "Template DIP" Then
MsgBox "Please do not edit This file! Use ""Save as"" prior to
editing!"
fExit = True
End If
End Sub

''your form code

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Bob Phillips" wrote in message
...
Private Sub UserForm_Initialize()
'other code removed
If Left(ActiveWorkbook.Name, 12) = "Template DIP" Then
MsgBox "Please do not edit This file! Use ""Save as"" prior to editing!"
Unload Me
End If
End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"Rick S." wrote in message
...
IO hope I can explain this, I have a userform that will open on a button
click from a worksheet. First thing I am doing is testing the file name
to
ensure the user won't overwrite the master file.
I can do that easily enough, the trouble I have is if the condition is
true
(they are using the master file) I prompt with a msgbox and then wish to
exit
the sub but the userform loads anyhow.
'=======
Private Sub UserForm_Initialize()
'other code removed
If Left(ActiveWorkbook.Name, 12) = "Template DIP" Then
MsgBox "Please do not edit This file! Use ""Save as"" prior to editing!"
End If
End Sub
'=======
No matter what I try I can not stop the userform from loading if the
above
condition is true.

--
Regards

VBA.Noob.Confused
XP Pro
Office 2007





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default UserForm_Initialize, how to exit sub based on condition?

I don't fully understand how you did it (setting a True condition), but you
did!
Testing appears to work just fine.
Thank you and have a great Holiday Weekend!

--
Regards

VBA.Noob.Confused
XP Pro
Office 2007



"Bob Phillips" wrote:

So it does, you can't unload it presumably because it isn't yet loaded.

Try this variation

Private fExit As Boolean

Private Sub UserForm_Activate()
If fExit Then Unload Me
End Sub

Private Sub UserForm_Initialize()
'other code removed
If Left(ActiveWorkbook.Name, 12) = "Template DIP" Then
MsgBox "Please do not edit This file! Use ""Save as"" prior to
editing!"
fExit = True
End If
End Sub

''your form code

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Bob Phillips" wrote in message
...
Private Sub UserForm_Initialize()
'other code removed
If Left(ActiveWorkbook.Name, 12) = "Template DIP" Then
MsgBox "Please do not edit This file! Use ""Save as"" prior to editing!"
Unload Me
End If
End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

"Rick S." wrote in message
...
IO hope I can explain this, I have a userform that will open on a button
click from a worksheet. First thing I am doing is testing the file name
to
ensure the user won't overwrite the master file.
I can do that easily enough, the trouble I have is if the condition is
true
(they are using the master file) I prompt with a msgbox and then wish to
exit
the sub but the userform loads anyhow.
'=======
Private Sub UserForm_Initialize()
'other code removed
If Left(ActiveWorkbook.Name, 12) = "Template DIP" Then
MsgBox "Please do not edit This file! Use ""Save as"" prior to editing!"
End If
End Sub
'=======
No matter what I try I can not stop the userform from loading if the
above
condition is true.

--
Regards

VBA.Noob.Confused
XP Pro
Office 2007






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
UserForm_Initialize Edwin Tam[_7_] Excel Programming 1 April 13th 06 04:49 PM
UserForm_Initialize Bob Phillips[_6_] Excel Programming 1 April 13th 06 04:43 PM
UserForm_Initialize() Joe Derr[_2_] Excel Programming 3 December 4th 04 04:23 AM
Exit a macro from an error condition ChuckM[_2_] Excel Programming 2 January 19th 04 02:12 PM
UserForm_Initialize Rob Excel Programming 2 January 15th 04 02:00 PM


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