Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: Why does VBA code in Private Sub kep running?

  1. #1
    Guest

    Default

    I'm using MS Excel 97. A worksheet has a combo box with vba code associated with it. When the combo box changes, so does data on a chart.

    The problem, however, is that the code in the combo box runs when I close the file. Why? (I don't want the code to run. Plus, I don't have any code elsewhere in the file where the OnClose event is used.) I don't understand why this happens when the code is in a private sub within the combo box control.

    Can anyone explain, and come up with a solution?

    Thanks,
    Pete

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    2,940
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default

    I think you're going to have to give more details. Is it the combobox from the Control Toolbox? Are you adding items through code or is it linked to a range? It would also be helpful if you post both the combobox code and the Before_Close code.

    Regards,
    D

  3. #3
    Guest

    Default

    Yes, the combobox is from the Control ToolBox, and the items listed are from a range.

    Here's the code for the combobox:
    (where the selection changes the pagefield
    of a pivot table)


    Private Sub cboHARP_Change()

    Application.ScreenUpdating = False
    ActiveCell.Activate
    ActiveSheet.PivotTables("pivotMEMBERSHIP").PivotFields("HARP").CurrentPage = cboHARP.Value

    If cboHARP.Text <> "ALL GRIPA" Then
    Range("c14") = cboHARP.Text
    Else
    Range("c14") = "GRIPA"
    End If

    Range("A1").Activate
    Application.ScreenUpdating = True

    End Sub



    As for code in the BeforeClose event, there is none:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    End Sub

    So, give the above info, what is triggering the code in the combobox private sub when closing the file?

    Thanks,
    Pete

    On 2002-02-27 10:51, dk wrote:
    I think you're going to have to give more details. Is it the combobox from the Control Toolbox? Are you adding items through code or is it linked to a range? It would also be helpful if you post both the combobox code and the Before_Close code.

    Regards,
    D

  4. #4
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    2,940
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default

    There's nothing that leaps out at me. I'll gladly have a look at the workbook if you want to send it (of course strip out any data you don't want others to see).

    dklann@lineone.net

    Regards,
    D

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •