PC Review


Reply
Thread Tools Rate Thread

Combobox_Change event fires on workbook close

 
 
Geoff
Guest
Posts: n/a
 
      17th Dec 2007
I have a workbook with a combobox 'CUPrevious' on one of its worksheets, with
change event coded (in the worksheet module) as follows:

Private Sub CUPrevious_Change()

Dim t As String

Application.ScreenUpdating = False
If Application.EnableEvents Then
Application.EnableEvents = False
End If

t = CUPrevious.LinkedCell

If Range(t).Value <> "" Then
Call CUFunc(Range(t).Text)
End If

Application.EnableEvents = True
Application.ScreenUpdating = True

End Sub

For some reason, whenever the workbook closes, this event is triggered and
if that sheet is not active at the time, the line
t = CUPrevious.LinkedCell
causes a runtime error as the value of linkedcell for the combobox seems to
be inaccessible. This is a problem which I have been able to get around by
calling the worksheet's Activate method in a Workbook.Before_Close procedure.
However, I don't see why the combobox change event should fire at all - the
value is not changing. Does anyone know why this is happening? More to the
point, is there some way to stop the event firing?

--
There are 10 types of people in the world - those who understand binary and
those who don't.
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      17th Dec 2007
Untested...

Try putting the linked cell on a different worksheet.

If that doesn't work, how about dropping the linked cell and assigning the value
of the combobox to the cell via code.

Geoff wrote:
>
> I have a workbook with a combobox 'CUPrevious' on one of its worksheets, with
> change event coded (in the worksheet module) as follows:
>
> Private Sub CUPrevious_Change()
>
> Dim t As String
>
> Application.ScreenUpdating = False
> If Application.EnableEvents Then
> Application.EnableEvents = False
> End If
>
> t = CUPrevious.LinkedCell
>
> If Range(t).Value <> "" Then
> Call CUFunc(Range(t).Text)
> End If
>
> Application.EnableEvents = True
> Application.ScreenUpdating = True
>
> End Sub
>
> For some reason, whenever the workbook closes, this event is triggered and
> if that sheet is not active at the time, the line
> t = CUPrevious.LinkedCell
> causes a runtime error as the value of linkedcell for the combobox seems to
> be inaccessible. This is a problem which I have been able to get around by
> calling the worksheet's Activate method in a Workbook.Before_Close procedure.
> However, I don't see why the combobox change event should fire at all - the
> value is not changing. Does anyone know why this is happening? More to the
> point, is there some way to stop the event firing?
>
> --
> There are 10 types of people in the world - those who understand binary and
> those who don't.


--

Dave Peterson
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      17th Dec 2007
In fact, if you have the listfillrange on the same sheet, you may want to move
that to a different worksheet, too.

Geoff wrote:
>
> I have a workbook with a combobox 'CUPrevious' on one of its worksheets, with
> change event coded (in the worksheet module) as follows:
>
> Private Sub CUPrevious_Change()
>
> Dim t As String
>
> Application.ScreenUpdating = False
> If Application.EnableEvents Then
> Application.EnableEvents = False
> End If
>
> t = CUPrevious.LinkedCell
>
> If Range(t).Value <> "" Then
> Call CUFunc(Range(t).Text)
> End If
>
> Application.EnableEvents = True
> Application.ScreenUpdating = True
>
> End Sub
>
> For some reason, whenever the workbook closes, this event is triggered and
> if that sheet is not active at the time, the line
> t = CUPrevious.LinkedCell
> causes a runtime error as the value of linkedcell for the combobox seems to
> be inaccessible. This is a problem which I have been able to get around by
> calling the worksheet's Activate method in a Workbook.Before_Close procedure.
> However, I don't see why the combobox change event should fire at all - the
> value is not changing. Does anyone know why this is happening? More to the
> point, is there some way to stop the event firing?
>
> --
> There are 10 types of people in the world - those who understand binary and
> those who don't.


--

Dave Peterson
 
Reply With Quote
 
Geoff
Guest
Posts: n/a
 
      17th Dec 2007
Thanks Dave

In the end I just changed the code in the change event as follows:

If t <> "" Then
If Range(t).Value <> "" Then Call AnzsicCU(Range(t).Text)
End If

Somewhat convoluted but it gets the job done for both normal operation of
the combobox and for the workbook close event. The linked cell could move to
a different worksheet but that would require rather more changes to the UI
than I would like to make at this point - thanks for the reply though

I'm still mystified as to why the change event fires at all, but at least I
can close the workbook...
--
There are 10 types of people in the world - those who understand binary and
those who don't.


"Dave Peterson" wrote:

> Untested...
>
> Try putting the linked cell on a different worksheet.
>
> If that doesn't work, how about dropping the linked cell and assigning the value
> of the combobox to the cell via code.
>
> Geoff wrote:
> >
> > I have a workbook with a combobox 'CUPrevious' on one of its worksheets, with
> > change event coded (in the worksheet module) as follows:
> >
> > Private Sub CUPrevious_Change()
> >
> > Dim t As String
> >
> > Application.ScreenUpdating = False
> > If Application.EnableEvents Then
> > Application.EnableEvents = False
> > End If
> >
> > t = CUPrevious.LinkedCell
> >
> > If Range(t).Value <> "" Then
> > Call CUFunc(Range(t).Text)
> > End If
> >
> > Application.EnableEvents = True
> > Application.ScreenUpdating = True
> >
> > End Sub
> >
> > For some reason, whenever the workbook closes, this event is triggered and
> > if that sheet is not active at the time, the line
> > t = CUPrevious.LinkedCell
> > causes a runtime error as the value of linkedcell for the combobox seems to
> > be inaccessible. This is a problem which I have been able to get around by
> > calling the worksheet's Activate method in a Workbook.Before_Close procedure.
> > However, I don't see why the combobox change event should fire at all - the
> > value is not changing. Does anyone know why this is happening? More to the
> > point, is there some way to stop the event firing?
> >
> > --
> > There are 10 types of people in the world - those who understand binary and
> > those who don't.

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combobox_change event fires when a workbooks is saved Paul W Smith Microsoft Excel Programming 3 18th May 2008 11:34 PM
combobox change fires on workbook close when textcol <>1 or -1 sophie Microsoft Excel Programming 2 26th Jan 2008 05:09 AM
ComboBox_Change Event to Populate another Combox Tobi Microsoft Excel Programming 4 31st Oct 2006 11:34 PM
Combobox_change event problem =?Utf-8?B?U2hhd24gRy4=?= Microsoft Excel Programming 2 18th Aug 2005 01:37 PM
comboBox TextChanged event fires twice because Items.Insert() fires the event too... Rob Hindman Microsoft Dot NET Framework Forms 2 25th Aug 2003 07:10 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:32 PM.