Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Getting error unloading Userform??

In a certain workbook, code in the ThisWorkbook module creates a new menu
with one item when the workbook opens. The one item calls a macro in a
general module in the workbook. The macro has one item:
Load UserForm1

The Form_Initialize code gets the name of every sheet in the workbook and
populates a ComboBox control. The form has an "Exit" CommandButton, with
two lines of code:
Set wb = Nothing
Unload Me

When I click the Exit button, the form unloads and disappears, but the code
then errors with 91: Object variable or With variable not set. The VBE
opens with the
Load UserForm1
line in the original macro highlighted in yellow.

How should I fix this?

Ed


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Getting error unloading Userform??

Ed,

Not quite sure what is calling whom when, but I believe
you should...
1. change the code for the exit button from
Unload Me to Me.Hide
2. and then...
add the line "Unload UserForm1" following the
"UserForm1.Show" line, where ever that is.

Regards,
Jim Cone
San Francisco, USA

"Ed" wrote in message
...
In a certain workbook, code in the ThisWorkbook module creates a new menu
with one item when the workbook opens. The one item calls a macro in a
general module in the workbook. The macro has one item:
Load UserForm1

The Form_Initialize code gets the name of every sheet in the workbook and
populates a ComboBox control. The form has an "Exit" CommandButton, with
two lines of code:
Set wb = Nothing
Unload Me

When I click the Exit button, the form unloads and disappears, but the code
then errors with 91: Object variable or With variable not set. The VBE
opens with the
Load UserForm1
line in the original macro highlighted in yellow.

How should I fix this?

Ed


  #3   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Getting error unloading Userform??

UserForm1.Show is in the Initialize code, right after the ComboBox loop
ends. If I put it there, wouldn't it unload the form right after showing
it?

Ed

"Jim Cone" wrote in message
...
Ed,

Not quite sure what is calling whom when, but I believe
you should...
1. change the code for the exit button from
Unload Me to Me.Hide
2. and then...
add the line "Unload UserForm1" following the
"UserForm1.Show" line, where ever that is.

Regards,
Jim Cone
San Francisco, USA

"Ed" wrote in message
...
In a certain workbook, code in the ThisWorkbook module creates a new menu
with one item when the workbook opens. The one item calls a macro in a
general module in the workbook. The macro has one item:
Load UserForm1

The Form_Initialize code gets the name of every sheet in the workbook and
populates a ComboBox control. The form has an "Exit" CommandButton, with
two lines of code:
Set wb = Nothing
Unload Me

When I click the Exit button, the form unloads and disappears, but the

code
then errors with 91: Object variable or With variable not set. The VBE
opens with the
Load UserForm1
line in the original macro highlighted in yellow.

How should I fix this?

Ed




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Getting error unloading Userform??

Ed,

No it won't. The normal sequence is...

'------------------
Sub Demo
'code here to check stuff

UserForm1.Show
'do stuff while form is shown - click option buttons etc.
'then hide the form by clicking a button on the form (Me.Hide)

'code here to check for any settings on the form, for instance
'an entry in a textbox or which option button was clicked.

Unload UserForm1 '(Me can't be used)
'additional code here
Set UserForm1 = Nothing
End Sub
'-------------------
Jim Cone
San Francisco, USA



"Ed" wrote in message
...
UserForm1.Show is in the Initialize code, right after the ComboBox loop
ends. If I put it there, wouldn't it unload the form right after showing
it?
Ed

"Jim Cone" wrote in message
...
Ed,

Not quite sure what is calling whom when, but I believe
you should...
1. change the code for the exit button from
Unload Me to Me.Hide
2. and then...
add the line "Unload UserForm1" following the
"UserForm1.Show" line, where ever that is.

Regards,
Jim Cone
San Francisco, USA



"Ed" wrote in message
...
In a certain workbook, code in the ThisWorkbook module creates a new menu
with one item when the workbook opens. The one item calls a macro in a
general module in the workbook. The macro has one item:
Load UserForm1

The Form_Initialize code gets the name of every sheet in the workbook and
populates a ComboBox control. The form has an "Exit" CommandButton, with
two lines of code:
Set wb = Nothing
Unload Me
When I click the Exit button, the form unloads and disappears, but the

code then errors with 91: Object variable or With variable not set. The VBE
opens with the Load UserForm1
line in the original macro highlighted in yellow.
How should I fix this?
Ed



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
Unloading UserForm not working Marston Excel Programming 2 August 17th 04 04:18 AM
Unloading userform in MSComm event Sunny[_4_] Excel Programming 0 June 10th 04 06:04 PM
Not Unloading a UserForm Mike[_49_] Excel Programming 1 January 29th 04 11:45 PM
Unloading A Form Chrissy[_4_] Excel Programming 1 October 15th 03 02:17 PM
Unloading an Add-In Jack Excel Programming 1 October 1st 03 09:39 AM


All times are GMT +1. The time now is 12:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"